
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An introduction to java gui programming, focusing on applets, gui-components, packages, and the java awt package. It covers creating and using components, exploring their properties, and using jbuilder7 design tool. The document also introduces layout managers and their role in organizing components.
Typology: Slides
1 / 24
This page cannot be seen from the preview
Don't miss anything!
An Introduction
Outline
Packages
java.awt javax.swings
Abstract Windowing Kit GUI-Components are drawn according to the underlying windowing system Initial set of Components developed AWT Components Buttons Text Fields Labels Text Areas Check Boxes Menus Radio Buttons Canvases Lists Scroll Panes Choices
First Button
public Button firstButton = new Button(“ Click It ”);
add(firstButton);
Button applet output
Adding few more buttons
import java.awt.*;
import java.applet.*;
public class ButtonApplet extends Applet{
//creating the button component
public Button firstButton = new Button(“One”);
public Button secondButton = new Button(“Two”);
public Button thirdButton = new Button(“Threet”);
public void init( ){
//adding to the applet
add(firstButton); add(secondButton); add(thirdButton); }
}
Layout Managers
Flow Layout GridLayout Border Layout CardLayout GridBagLayout Null layout
The default layout manager
Using Layout managers
Create the container class e.g. applet Set layout
setLayout(Object of a Layout Class)
Flow Layout…cont..
Using Flow Layout constructor 1
import java.awt.; import java.applet.;
public class flowLayoutTest extends Applet{
public FlowLayout myFlowLayout=new FlowLayout(); Button B=new Button(“Click It”);
public void init(){ setLayout(myFlowLayout);
add(B); } }
Flow layout cont..
import java.awt.; import java.applet.;
public class flowLayoutTest extends Applet{
public FlowLayout
Button B=new Button(“Click It”);
public void init(){ setLayout(myFlowLayout); add(B); } }
Using Labels
Labels..
A label for a button import java.awt.; import java.applet.;
public class flowLayoutTest extends Applet{
public FlowLayout myFlowLayout= newFlowLayout((FlowLayout.Right );
Label label_save=new Label( “Save”); Button B=new Button(“Save”);
public void init(){
setLayout(myFlowLayout); add(label_save); add(B); }}
Using Text Areas
Creates an empty text area with default size (9 rows,47 columns)
Creates a text area and displays the given text
Creates a text area according to the given number of rows and coumns
Adds text at the end of the current text in the text area
Adds text at specified character position
Event Handling
A button click Clicking a check box
Writing text to a field Clicking on the applet surface
Depricated method previously used for handling events Cannot deal all sorts of events Syntax public boolean action(Event evnt, Object obj){ -------code to perform some actions----------- }