[PDF] GUI Programming Java and GUIs. • There are





Previous PDF Next PDF



Abstract Window Toolkit Overview

The Java 1.1 JDK ( Java Developer's Kit) occurred in December 1996. This release includes many improvements and additions to AWT and is a major step for- ward 



Untitled

JAVA provides a rich set of libraries to create Graphical User Interface (GUI) objects in an platform independent way. Abstract Window Toolkit (AWT) is a 



Introduction to Abstract Window Toolkit:(AWT)

class in java.lang package. ? AWT is used to build the graphical user interface with standard windowing elements.



AWT AWT stands for Abstract Window Toolkit. It is a platform

It is a platform dependent API for creating Graphical User Interface (GUI) for java programs. Why AWT is platform dependent? Java AWT calls native platform ( 



Difference Between AWT and Swing Key Difference - AWT vs Swing

05-Feb-2018 difference between AWT and Swing is that AWT is Java's original platform dependent windowing graphics



Introducing AWT

•The Abstract Window Toolkit (AWT) was Java's first. GUI framework. Component An abstract superclass for various AWT components. Container.



GUI Programming

Java and GUIs. • There are two primary built-?in packages that provide. GUI components in Java. – java.awt.*. – java.swing.*. • The Abstract Window Toolkit 



The AWT Applets

https://users.cs.fiu.edu/~weiss/cop4338_spr02/lectures/AWT/awt.pdf





Introduction to GUIs (Graphical User Interfaces) Interactive Programs

How does Java do GUIs? 4. Java Support for Building GUIs. • Java Foundation Classes. ? Classes for building GUIs. ? Major components. ? awt and swing.

GUIProgramming

CMSC202

WhyJavaGUIDevelopment?

• A>erallCMSC202isisaboutObjectOrientedProgramming,notGUIs • GUIsareagoodexampleofOOP• GUIsareanotherexampleofcontainers

JavaandGUIs

• Therearetwoprimarybuilt-inpackagesthatprovideGUIcomponentsinJava - java.awt.*- java.swing.* • TheAbstractWindowToolkit(AWT) - Java'soriginalGUItoolkit- LeveragesnaSvetoolkitstodrawwidgets • Swing - Offersamorecompletesetofwidgets- SystemorJavalookandfeel- LeveragesAWTthroughoutAPIs

Containers

• InJava,allGUIcomponentsgointoaContainer-whichissimplyawidgetthatcancontainotherwidgets • Atop-levelcontainercanstandaloneina windowenvironment - e.g.JFrame • Somecontainersmayonlybeaddedtoother containers - e.g.JPanel

Components

• AcomponentissimplyanobjectthathasagraphicalrepresentaSonthatcanbedisplayedonscreen • Acomponentactsasabaseclassforallswing components,excepttoplevelcontainers • Examplesofcomponentsinclude: - JBuYon,JComboBox,JLabel,JList,JMenuBar,

JPanel,JSlider,JSpinner,JTable,etc...

JFrame

• AJFrameiso>enthehighest-levelwidgetinyourapplicaSoninwhichallotherwidgetswillgetpacked • JFramesareusuallyconstructedusingthe followingconstructor: public JFrame(String title);

CommonJFrameMethods

• add(Componentc) - addsobjectstotheframe • setVisible(booleanb) - makestheframevisible • setLocaSon(intx,inty) - alignstople>cornerofframewithcoordinatesonscreen • setSize(intwidth,intheight) - setssizeofframeinpixels • setDefaultCloseOperaSon(intoperaSon) - defineswhatshouldhappenwhenthewindowisclosed,

JFrameExample

import javax.swing.JFrame;!import javax.swing.WindowConstants;!!public class UpperCaseConverter extends JFrame {!!"public UpperCaseConverter() {!""super("Upper Case Converter");!""setLocation(100, 100);!""setSize(480, 320);!""setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);!"}!!"public static void main(String[] args) {!""UpperCaseConverter ucc = new UpperCaseConverter();!""ucc.setVisible(true);!"}!!}

JFrameExample

LayoutManagers

• EverycontainerhasanunderlyingdefaultLayoutManager • TheLayoutManagerdetermines: - Thesizeoftheobjectsinthecontainerand- Howtheobjectswillbelaidout • ThedefaultLayoutManagerforaJFrameisa

BorderLayout

BorderLayout

• TheBorderLayoutmanagerdividescontainerintofiveregions - BorderLayout.NORTH- BorderLayout.SOUTH- BorderLayout.CENTER- BorderLayout.EAST- BorderLayout.WEST

• Onecomponentperregion• Componenttakessizeofregion• Centerregionisgreedy• Componentsareaddedtocenterbydefault

JBuYon

• AJBuYonprovidesabasicbuYonthatausercaninteractwith • AJBuYonmayconsistofacombinaSonoflabel - JBuYon(Iconicon) • CreatesabuYonwithanicon - JBuYon(Stringtext) • CreatesabuYonwithtext - JBuYon(Stringtext,Iconicon) • CreatesabuYonwithiniSaltextandanicon

BorderLayoutExample

import java.awt.BorderLayout;!!import javax.swing.JButton;!import javax.swing.JFrame;!!public class BorderLayoutExample extends JFrame {!"! public BorderLayoutExample(String name) {! super(name);! setSize(300, 300);! add(new JButton("North"), BorderLayout.NORTH);! add(new JButton("South"), BorderLayout.SOUTH);! add(new JButton("East"), BorderLayout.EAST);! add(new JButton("West"), BorderLayout.WEST);! add(new JButton("Center"), BorderLayout.CENTER);! }! public static void main(String args[]) {! BorderLayoutExample b = new BorderLayoutExample("BorderLayoutExample");! b.setVisible(true);! }!}

BorderLayoutExample

JPanel

• SaywewanttoputseveralbuYonsintheNorthregionoftheGUI,butBorderLayoutonlyallowsonecomponentperregion...

• AddasecondlevelcontainerlikeaJPanel• JPanelshaveaFlowLayoutmanagerbydefault

FlowLayout

• LayscomponentsinafluiddirecSonasdeterminedbyitsorientaSon • Bydefault,orientaSonisL→R,T→B• PossibletosetthehorizontalandverScal widthbetweencomponents • Componentstakepreferredsize - ForbuYons,preferredsizeisthesizeofthetext withinthem

FlowLayout

// ...!"!public UpperCaseConverter() {!! // code from previous slides ...!"!"JPanel topPanel = new JPanel();!"JButton upperButton = new JButton("To Upper");!"JButton clearButton = new JButton("Clear");!"topPanel.add(upperButton);!"topPanel.add(clearButton);!"add(topPanel, BorderLayout.NORTH);!}!!// ...

FlowLayout

JLabel

• TheJLabelrepresentsastaSclabel • LikebuYons,theycanconsistoftextand/orimagesandare - JLabel() • CreatesaJLabelinstancewithnoimageandwithanemptystringfor theStle. - JLabel(Iconimage) • CreatesaJLabelinstancewiththespecifiedimage. - JLabel(Stringtext) • CreatesaJLabelinstancewiththespecifiedtext. - JLabel(Stringtext,Iconicon,inthorizontalAlignment) • CreatesaJLabelinstancewiththespecifiedtext,image,and horizontalalignment

JTextField

• AJTextFieldprovidesanentryforasinglelineoftext • AJTextFieldmaybeconstructedwithasetwidthorwith - JTextField() • ConstructsanewTextField - JTextField(intcolumns) • ConstructsanewemptyTextFieldwiththespecifiednumberof columns - JTextField(Stringtext) • ConstructsanewTextFieldiniSalizedwiththespecifiedtext - JTextField(Stringtext,intcolumns) • ConstructsanewTextFieldiniSalizedwiththespecifiedtextand columns

OverridingaPanel'sLayoutManager

• Youcanalsoover-ridethelayoutmanagerformostcontainers • Forexample,wecanchangeaJPanel'slayout

OverridingaPanel'sLayoutManager

// ...!"!public UpperCaseConverter() {!!"// code from previous slides ...!!"JPanel bottomPanel = new JPanel();!"bottomPanel.setLayout(new BorderLayout());!"JLabel enterTextLabel = new JLabel("Enter text: ");!"JTextField textField = new JTextField(20);!"bottomPanel.add(enterTextLabel, BorderLayout.WEST);!"bottomPanel.add(textField, BorderLayout.CENTER);!"add(bottomPanel, BorderLayout.SOUTH);!}!!// ...!

OverridingaPanel'sLayoutManager

JTextArea

• AJTextAreaissimilartoaJTextField,exceptthatitiscapableofdisplayingmulSplelinesoftext • AJTextAreacanbeconstructedwithagivensizeand/or - JTextArea() • ConstructsanewTextArea. - JTextArea(introws,intcolumns) • ConstructsanewemptyTextAreawiththespecifiednumberofrows andcolumns. - JTextArea(Stringtext) • ConstructsanewTextAreawiththespecifiedtextdisplayed. - JTextArea(Stringtext,introws,intcolumns) • ConstructsanewTextAreawiththespecifiedtextandnumberof rowsandcolumns.

JTextArea

// ...!"!public UpperCaseConverter() {!!"// code from previous slides ...!!"JTextArea textArea = new JTextArea();!"textArea.setEditable(false);!"add(textArea, BorderLayout.CENTER);!}!!// ...!

JTextArea

RespondingtoAcSons

• CurrentlyourbuYondoesn'tdoanythingwhenpressed,torespondtothisacSonweneedtoaddanAcSonListener • AnAcSonListenercanbeaddedtoabuYonusing thefollowingmethod: - publicvoidaddAcSonListener(AcSonListenerl); • TheAcSonListenerinterfaceisquitesimple,in - voidacSonPerformed(AcSonEvente)

LejngourclassimplementAcSonListener

• OneapproachtoimplemenSnganAcSonListeneristohave"this"classimplementit button.addActionListener(this); • AnotherapproachistoactuallydefineaninlineanonymousclasstohandletheacSons • Theclassisconsideredinlineasitisdeclared inthecontextofanotherclass • Itisalsoconsideredanonymous,asthenew classisnotgivenaname

SimpleAcSonListeners

// ...!"!public UpperCaseConverter() {!!"// code from previous slides ...!"upperButton.addActionListener(new ActionListener() {!""public void actionPerformed(ActionEvent e) {!"""System.out.println("button pressed");!""}!"});"!"clearButton.addActionListener(new ActionListener() {!""public void actionPerformed(ActionEvent e) {!"""System.out.println("button pressed");!""}!"});!}!!// ...!

ManipulaSngWidgets

• RatherthansimplyprinSng"buYonpressed"let'smodifyourAcSonListenertoreadthevalueoftheJTextFieldandwritetotheJTextArea

• Assuchwe'regoingtoneedtoreferencesto thosewidgets - wehave2opSons - Storethewidgetsasmembersoftheclass- Markthewidgetreferencesasfinal

MoreInteresSngAcSonListeners

// ...!"!public UpperCaseConverter() {!!"// code from previous slides...!"// with upperButton and clearButton declared final!!"upperButton.addActionListener(new ActionListener() {!""public void actionPerformed(ActionEvent e) {!"""textArea.setText(textField.getText().toUpperCase());!""}!"});!"!"clearButton.addActionListener(new ActionListener() {!""public void actionPerformed(ActionEvent e) {!"""textArea.setText("");!"""textField.setText("");!"""textField.requestFocus();!""}!"});!}!// ...!

MoreInteresSngAcSonListeners

LookandFeel

• Bydefault,JavausesitsownLookandFeel • Ifyou'dliketousethenaSvelookandfeelfor

try {!"UIManager.setLookAndFeel(!""UIManager.getSystemLookAndFeelClassName()!");!} catch (Exception e) {!"// handle or ignore!}

ScratchingtheSurface

• Whatwe'velookedathereisreallyjusttheSpoftheiceberg,therealottoswing • Someselectedreferences...

- AVisualGuidetoLayoutManagers- SwingFeatures- AVisualGuidetoSwingComponents- Trail:CreaSngaGUIWithJFC/Swing

quotesdbs_dbs21.pdfusesText_27
[PDF] abstract writing format example

[PDF] abstraction in oop definition

[PDF] abstraction in oop java

[PDF] abstraction in oop python

[PDF] abstraction in oops with example

[PDF] abstraction in oops with example in java

[PDF] ac 120/230 v (50/60 hz) to watts

[PDF] ac 60hz to 50hz converter

[PDF] ac capacity calculation

[PDF] ac circuits problems and solutions pdf

[PDF] ac current

[PDF] ac frequency us

[PDF] ac tonnage calculation formula

[PDF] ac unit calculator

[PDF] ac2o dmap mechanism