Beruflich Dokumente
Kultur Dokumente
Lab – 9 (AWT)
Objectives
End of this lab session student will be able
package testawt;
/**
*
* @author khaja
*/
import java.awt.Frame;
import java.awt.Label;
public class Testawt
{
Testawt()
{
Frame fm=new Frame(); //Creating a frame.
Label lb = new Label("welcome to java graphics"); //Creating a label
fm.add(lb); //adding label to the frame.
fm.setSize(300, 300); //setting frame size.
fm.setVisible(true); //set frame visibilty true.
}
public static void main(String args[])
{
Testawt ta = new Testawt();
}
}
package testawt;
/**
*
* @author khaja
*/
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
package testawt;
/**
*
* @author khaja
*/
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class First
{
JFrame jf;
public First() {
jf = new JFrame("MyWindow"); //Creating a JFrame with name MyWindow.
JButton btn = new JButton("Say Hello"); //Creating a Button.
jf.add(btn); //adding button to frame.
jf.setLayout(new FlowLayout()); //setting layout using FlowLayout object.
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //setting close operation.
jf.setSize(400, 400); //setting size
jf.setVisible(true); //setting frame visibilty
}
public static void main(String[] args)
{
new First();
}
}
package testawt;
/**
*
* @author khaja
*/
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Second extends JFrame
{
public Second()
{
setTitle("MyWindow");
JLabel lb = new JLabel("Welcome to My Second Window"); //Creating a label.
add(lb); //adding label to frame.
setLayout(new FlowLayout()); //setting layout using FlowLayout object.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //setting close operation.
setSize(400, 400); //setting size
setVisible(true); //setting frame visibilty
}
public static void main(String[] args)
{
new Second();
}
}
package testawt;
/**
*
* @author khaja
*/
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class testswing extends JFrame
{
testswing()
{
JButton bt1 = new JButton("Yes"); //Creating a Yes Button.
JButton bt2 = new JButton("No"); //Creating a No Button.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //setting close operation.
setLayout(new FlowLayout()); //setting layout using FlowLayout object
setSize(400, 400); //setting size of Jframe
add(bt1); //adding Yes button to frame.
add(bt2); //adding No button to frame.
setVisible(true);
}
public static void main(String[] args)
{
new testswing();
}
}
package testawt;
/**
*
* @author khaja
*/
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class MyTextField extends JFrame
{
public MyTextField()
{
JTextField jtf = new JTextField(20); //creating JTextField.
add(jtf); //adding JTextField to frame.
setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 400);
setVisible(true);
}
public static void main(String[] args)
{
new MyTextField();
}
}
package testawt;
/**
*
* @author khaja
*/
import java.awt.FlowLayout;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
public class Test extends JFrame
{
public Test()
{
JCheckBox jcb = new JCheckBox("yes"); //creating JCheckBox.
add(jcb); //adding JCheckBox to frame.
jcb = new JCheckBox("no"); //creating JCheckBox.
add(jcb); //adding JCheckBox to frame.
jcb = new JCheckBox("maybe"); //creating JCheckBox.
add(jcb); //adding JCheckBox to frame.
setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 400);
setVisible(true);
}
public static void main(String[] args)
{
new Test();
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package testawt;
/**
*
* @author khaja
*/
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
public class Radio extends JFrame
{
public Radio()
{
JRadioButton jcb = new JRadioButton("A"); //creating JRadioButton.
add(jcb); //adding JRadioButton to frame.
jcb = new JRadioButton("B"); //creating JRadioButton.
add(jcb); //adding JRadioButton to frame.
jcb = new JRadioButton("C"); //creating JRadioButton.
add(jcb); //adding JRadioButton to frame.
jcb = new JRadioButton("none");
add(jcb);
setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 400);
setVisible(true);
package testawt;
/**
*
* @author khaja
*/
import java.awt.FlowLayout;
import javax.swing.JComboBox;
import javax.swing.JFrame;
public class Combobox extends JFrame
{
String name[] = {"Abhi","Adam","Alex","Ashkay"}; //list of name.
public Combobox()
{
JComboBox jc = new JComboBox(name); //initialzing combo box with list of name.
add(jc); //adding JComboBox to frame.
setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 400);
setVisible(true);
}
public static void main(String[] args)
{
new Combobox();
}
}