Forums Register Login

Swings

+Pie Number of slices to send: Send
import javax.swing.*;
import jav.awt.*;
import java.awt.event.*;

public interface Inter
{
public void methodInter();
}

public class Lucky
{
public static void main(String args[])
{
Lucky lk = new Lucky();
lk.run();
}

public void run()
{
JFrame fm;
JPanel pb, pm;
JSeparator sep;
JTextField txf;
String titlename, authorname;

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?
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1070 times.
Similar Threads
JDialog components not refreshing
How to use CardLayout Manager
problem with reverse tabbing
JFrame panels NOT showing. WHY??
problem with ActionListener of jTextField
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:46:23.