2 Explain the difference between a combo box and a dialog bo
2. Explain the difference between a combo box and a dialog box.
3. Give an example of a common use of a dialog box.
4. Write a short snippet of code that creates a J Panel objectcalled p1, and creates a border around it containing the title \"this is a JPanel.\"
5. Write a keyPressed method that behaves as follows. If the user presses the up arrow, the method should output \"You pressed up\"using the System.out.printin method. Ifthe user presses the down arrow, the method should output \"You pressed down\" using the System.out.printin method.
6. Should a component ever be disabled? Why or why not?
7. Write a program that produces a simple GUI that has a single button labeled \"Push Me.\"
8. Write a short class that represents a panel with a single radio button that has the option \"Yes\"and the option \"No.\" By default, the Yes button should be checked.
9. Suppose we have created a class called MyGUI, which represents a GUI. Write a program that creates a JFrame object, adds a MyGUI object to the frame and makes it visible.
10. Write a short class that represents a panel with a single slidert hat has values from 0 to 250, with large tick marks in increments of 50 and small tick marks in increments of 10.
Solution
Answers
2.
A combo box has a list of options from which the user has to select the most appropriate option.
A dialog box has an empty space where the user has to enter data most specific to which the box is meant for.
3.
A common use of a dialog box is collecting information from user, for example, Name, Phone Number, etc.
6.
A component can be disabled if the data record from that component is not important for pasing purpose.
7.
import javax.swing.*;
public class GUIPush {
public static void main(String [] args) {
// creating the JFrame object
JFrame gui = new JFrame();
// setting the layout manager
gui.setLayout(new FlowLayout());
// adding a label and a button
JLabel msg = new JLabel(\"to do\");
gui.add(msg);
JButton push = new JButton(\"push me\");
gui.add(push);
// setting up a listener
ButtonListener bulist = new ButtonListener();
blist.setLabel(msg);
push.addActionListener(bulist);
// making the program terminate when the window is closed
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// giving the window a title
gui.setTitle(\"GUI Push Button\");
// setting the size of the window
gui.setSize(500,250); // 500 pixels wide and 250 pixels high
// making the window visible
gui.setVisible(true);
} // main method close
} // GUIPush class close

