Skip to main content



      Home
Home » Newcomers » Newcomers » *** NOT WORKING ***(JComponents Issue)
*** NOT WORKING *** [message #1802523] Mon, 11 February 2019 06:46 Go to next message
Eclipse UserFriend
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);



}
}


Re: *** NOT WORKING *** [message #1802624 is a reply to message #1802523] Tue, 12 February 2019 17:32 Go to previous message
Eclipse UserFriend
This isn't a general programming question forum. You might find more help at javaranch.com or stackoverflow.com .
Previous Topic:Jetty webserver launch failing and giving " fatal error: 40: no cipher suites in common"
Next Topic:Command to clean workspace
Goto Forum:
  


Current Time: Sun Jul 06 11:28:33 EDT 2025

Powered by FUDForum. Page generated in 0.08039 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top