*** NOT WORKING *** [message #1802523] |
Mon, 11 February 2019 11:46 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
John Langley![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=yegnal%40yahoo.com) Messages: 1 Registered: February 2019 |
Junior Member |
|
|
In the code below I've created some simple items for a control bar in a simple program while learning how to code Java.
The behavior of one of the items (JButton "Clear") doesn't appear clicked even when it is if fact, clicked. No indication that it was depressed even though it actually works to remove all graphical elements from the canvas of this simple program.
All the other items do not work. Checkbox won't allow itself to be checked, radiobuttons the same, and the combobox drops down but also will not allow a particular selection.
Far as I can tell, I have all the right imports, at this point I'm at a loss to explain why things aren't functioning....
Eclipse IDE for Java Developers
Version: 2018-12 (4.10.0)
Build id: 20181214-0600
Code:
import acm.program.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.ButtonGroup;
import javax.swing.JRadioButton;
import javax.swing.JComboBox;
public class testprogram extends GraphicsProgram {
private JCheckBox bx;
private JButton clear;
private JRadioButton small;
private JRadioButton medium;
private JRadioButton large;
private JComboBox clr;
private String[] clrs = {"Black", "Red", "Green"};
public void init () {
clear = new JButton ("Clear");
add(clear, SOUTH);
putRadioButtons();
bx = new JCheckBox ("Test");
add(bx, SOUTH);
clr = new JComboBox (clrs);
clr.setEditable(false);
add(clr, SOUTH);
addMouseListeners();
addActionListeners();
}
@Override
public void actionPerformed (ActionEvent e) {
if (e.getActionCommand().equals("Clear")) {
removeAll();
}
}
private void putRadioButtons (){
small = new JRadioButton ("Small");
medium = new JRadioButton ("Medium");
large = new JRadioButton ("Large");
ButtonGroup sizeGroup = new ButtonGroup ();
sizeGroup.add(small);
sizeGroup.add(medium);
medium.setSelected(true);
sizeGroup.add(large);
add(small, SOUTH);
add(medium, SOUTH);
add(large, SOUTH);
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.07311 seconds