create a graphical user interface with various components. To create listeners f
ID: 3685972 • Letter: C
Question
create a graphical user interface with various components. To create listeners for JCheckBox, JRadioButton and JTextField. To enter multiple-line texts using JTextArea. To select a single item using JComboBox and to select a range of values using JScrollBar. Please use the theme of sports or food related. GUI CoMPONENTS Objectives Due Ayl 5, 2016 To create graphical user interfaces with various user-interface components (S817.2-17.8). To create listeners for JCheckBox,JRadioButton, and TextField (817.2) To enter multiple-line texts using 3TextArea ($17.3). To select a single item using-CoaboBo% ($17.4). To select a single or multiple tems using J List (§ 17.5). To select a range ofvalues using ]Scro11 Bar ($17.6) To select a range of values using between 3ScrollBar and s1idr ($17.7). 1Explanation / Answer
Java Class for Jcheck box,Jscrollbar……
public class MainView extends JFrame implements ActionListener{
// Radio Buttons
JRadioButton radioButton1 = new JRadioButton("Button 1");
JRadioButton radioButton2 = new JRadioButton("Button 2");
//check box
JCheckBox checkBox = new JCheckBox("CheckBox");
ButtonGroup buttonGroup = new ButtonGroup();
public MainView() {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(300, 100);
setLayout(new GridLayout());
buttonGroup.add(radioButton1);
buttonGroup.add(radioButton2);
radioButton1.addActionListener(this);
radioButton2.addActionListener(this);
radioButton2.setSelected(true); // remove to have no button selected
// scroll bar
label = new JLabel();
setLayout(new BorderLayout());
JScrollBar hbar = new JScrollBar(JScrollBar.HORIZONTAL, 30, 20, 0, 300);
JScrollBar vbar = new JScrollBar(JScrollBar.VERTICAL, 30, 40, 0, 300);
hbar.setUnitIncrement(2);
hbar.setBlockIncrement(1);
hbar.addAdjustmentListener(new MyAdjustmentListener());
vbar.addAdjustmentListener(new MyAdjustmentListener());
add(hbar, BorderLayout.SOUTH);
add(vbar, BorderLayout.EAST);
add(label, BorderLayout.CENTER);
// ActionListener for CheckBox
checkBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO: Your action here
}
});
getContentPane().add(radioButton1);
getContentPane().add(radioButton2);
getContentPane().add(checkBox);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
checkBox.setVisible(radioButton2.isSelected());
}
public static void main(String[] args) {
new MainView();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.