File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Swings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swings" Watch "Swings" New topic
Author

Swings

Lucky Singh
Ranch Hand

Joined: Jan 19, 2004
Posts: 125
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?
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
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 ]

My Java Freeware:<br />MACCC - <a href="http://maccc.pipasoft.com" target="_blank" rel="nofollow">http://maccc.pipasoft.com</a><br />Nator - <a href="http://nator.pipasoft.com" target="_blank" rel="nofollow">http://nator.pipasoft.com</a>
Lucky Singh
Ranch Hand

Joined: Jan 19, 2004
Posts: 125
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
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://aspose.com/file-tools
 
subject: Swings
 
Similar Threads
problem with ActionListener of jTextField
JFrame panels NOT showing. WHY??
problem with reverse tabbing
JDialog components not refreshing
How to use CardLayout Manager