Академический Документы
Профессиональный Документы
Культура Документы
Activity I Q1. Write the following code in the file GUITest.java. Compile it and Observe the o/p? import java.awt.*; import javax.swing.*; public class GUITest { public static void main(String[] args) { JFrame frame=new JFrame(); //create a new frame JButton button1 = new JButton("Click me"); JButton button2 = new JButton("Click me too"); JPanel panel= new Jpanel(); //add a panel to the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(BorderLayout.WEST, panel); panel.add(BorderLayout.SOUTH, button1); //add buttons to the panel panel.add(BorderLayout.NORTH, button2); frame.setSize(400,600); //set the default size of the frame
Activity II Q2. Write the following code in the file GUITest.java. Compile it and Observe the o/p? import java.awt.BorderLayout; import java.awt.Color; import javax.swing.*; public class Panels { public static void main(String[] args) { JFrame frame= new JFrame("Panel Test"); JPanel colorPanel,textButtonPanel; colorPanel = new JPanel(); textButtonPanel = new JPanel(); JButton red= new JButton("Red"); JButton blue= new JButton("blue"); JButton hello = new JButton("Hello");
1|Page
import java.awt.*; import javax.swing.*; import java.awt.event.*; class Buttonlistener implements ActionListener { private JLabel l1 ; Buttonlistener(JLabel l1) { this.l1 = l1; } public void actionPerformed(ActionEvent ae) { String str = ae.getActionCommand(); // Read the Command who has generated ActionEvent if(str.equals("Hello")) l1.setText("Hello How are you"); if(str.equals("Hi")) l1.setText("Hi How are you"); if(str.equals("RED")) l1.setForeground(Color.red); if(str.equals("GREEN")) l1.setForeground(Color.green);
2|Page
3|Page