This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swings

 
Lucky Singh
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 299
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Lucky Singh
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1535
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic