This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
fm = new JFrame("Welcome!"); // create a new frame. pb = new JPanel(); // create top panel which has a radio button. pm = new JPanel(); sep = new JSeparator(); pb.setLayout(new FlowLayout()); // setting layout so can add more //buttons in future. class JRadioButton1 extends JRadioButton implements Inter { private ActionListener al1 = new ActionListener() { public void actionPerformed(ActionEvent e1) { txf.setText((JRadioButton)e1.getSource()).getText(); } };
public JRadioButton1(String header) { pb.add(super("One radion button")); // creating a radio button and adding it to top panel. }
// implementing method Inter by creating 2 new String objects. public void methodInter() { titlename = new String("Charles Dickens"); authorname = new String("Great Expectations"); } // want to set these String objects to a text field and display the // textfield. txf = new JTextField(titlename + "-" + authorname); txf.setEditable(false);
pm.add(txf); // adding the textfield to the bottom panel. Container fc = fm.getContentPane(); fc.add(pm, BorderLayout.SOUTH);// adding both panels to the //frame. fc.add(pb, BorderLayout.NORTH);
//end of inner class RadioButton1
fm.setVisible(true); fm.pack(); } }//end of class Lucky.
Hi, Can anyone please tell me whats wrong and how to I correct it?
Brian Pipa
Ranch Hand
Joined: Sep 29, 2003
Posts: 299
posted
0
Can you tell us what this program is supposed to do? You might have better success if you break this down into a few different classes and try and get each one to compile separately. The way you have them all intermingled is quite confusing. It looks like you could break this into these classes: Lucky.java Inter.java JRadioButton1.java You should also rename some of the classes/variables ot be more descriptive. An interface named Inter tells me NOTHING. 2nd line: import jav.awt.*; should be import java.awt.*; [ January 19, 2004: Message edited by: Brian Pipa ]
Inter is an interphase having one method. Lucky is a class which has the main method and a run method. When an instance of Lucky is created in main, we use that to call the run method. When the run method is called, a frame is created and 2 panels are also created. A listener is created which will respond when the radio button is clicked. Within class Lucky there is an inner class called RadioButton1 which extends the JRadioButton class and this implements interphase Inter. A radio button is created within the constructor of this inner class. When the radio button is clicked, 2 string objects are created and they are to be displayed in the text field. Basically, trying out something with inner classes and radio buttons.
Craig Wood
Ranch Hand
Joined: Jan 14, 2004
Posts: 1535
posted
0
I couldn't find much to work with in the code you posted so I made up this example app with inner classes, radio buttons and events.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.