Java Programming Name:__________________________________________________Subject:______________________ Yr&Section:__________________________________Course:__________________________________ 1.The following program briefly demonstrates all three types of option panes: // Shows several JOptionPane windows on the screen. import javax.swing.*; import javax.swing.JOptionPane; public class BSIT1Y_JOptionPane { private static int choice; public static void main(String[] args) { JOptionPane.showMessageDialog(null," Wellcome to GUI JOptionPane"); // Input Dialog box String name = JOptionPane.showInputDialog(null, "What is your name?"); String section = JOptionPane.showInputDialog(null, "What is your section?"); //Display the inoutted information int choice = JOptionPane.showConfirmDialog(null, "Do you like programming, "); if (choice == JOptionPane.YES_OPTION){ JOptionPane.showMessageDialog(null, "I am " + name + " - " + section + " and I like programming"); } else if(choice == JOptionPane.NO_OPTION){ JOptionPane.showMessageDialog(null, "I am " + name + " - " + section + " and I Dont like programming"); } else{ JOptionPane.showMessageDialog(null," Cancelled "); } } } Java Programming Program and Output 2. // Uses JOptionPane windows for numeric input. import javax.swing.*; // for GUI components public class UseOptionPanes2 { public static void main(String[] args) { String ageText = JOptionPane.showInputDialog(null, "How old are you?"); int age = Integer.parseInt(ageText); String moneyText = JOptionPane.showInputDialog(null, "How much money do you have?"); double money = Double.parseDouble(moneyText); JOptionPane.showMessageDialog(null, "If you can double your money each year,\n" + "You'll have " + (money * 32) + "dollars at age " + (age + 5) + "!"); } } Program and Output 3. // Sets several properties of a window frame. import java.awt.*; // for Dimension Java Programming import javax.swing.*; // for GUI components public class SimpleFrame2 { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setForeground(Color.WHITE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocation(new Point(10, 50)); frame.setSize(new Dimension(300, 120)); frame.setTitle("A frame"); frame.setVisible(true); } } Program and Output 4. // Creates a frame containing two buttons. Java Programming import java.awt.Color; import java.awt.Dimension; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.*; /** * * @author Rodel */ public class BSIT1Y_JFRAME { public static void main (String [] args){ JFrame frame = new JFrame(); frame.setSize(600,600); frame.setTitle("first frame"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBackground(Color.BLUE); frame.setLayout(null); frame.setVisible(true); JLabel label = new JLabel("LABEL"); label.setBounds(50,50,50,50); frame.add(label); // button component JButton button = new JButton("click button"); button.setSize(100,200); button.setBounds(200,100,100,100); button.setForeground(Color.LIGHT_GRAY); button.setBackground(Color.yellow); frame.add(button); JButton button1 = new JButton("click button 1"); button1.setSize(100,200); button1.setBounds(100,100,100,100); button1.setForeground(Color.yellow); button.setBackground(Color.GREEN); frame.add(button1); JPanel panel = new JPanel(); panel.setSize(400,400); panel.setBounds(100,50,300,200); panel.setBackground(Color.MAGENTA); Java Programming frame.add(panel); } } Program and Output