having problem while displaying graphical content in eclipse

0 Ringchhen Lama · February 22, 2015
/images/forum/upload/2015-02-22/2cd3a52e62c404ebf26be49d0ff9dc5c.JPG/*this program is done by Bucky but it doesn't run properly. 
Below is the code and i have attached the image file of the ouptut 
of this program*/
package whatever;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class Gui extends JFrame {
private JTextField tf;
private Font pf;
private Font itf;
private Font bf;
private Font bif;
private JRadioButton pb;
private JRadioButton itb;
private JRadioButton bb;
private JRadioButton bib;
private ButtonGroup group;
public Gui() {
super("the title");
tf=new JTextField("Ringchhen Lama is cool and hot",20);
add(tf);
pb=new JRadioButton("Plain",true);
itb=new JRadioButton("Italic",false);
bb=new JRadioButton("Bold",false);
bib=new JRadioButton("Bold & Italic",false);
add(pb);
add(itb);
add(bb);
add(bib);

group=new ButtonGroup();
group.add(pb);
group.add(itb);
group.add(bb);
group.add(bib);

pf=new Font("sherif",Font.PLAIN,20);
itf=new Font("sherif",Font.ITALIC,20);
bf=new Font("sherif",Font.BOLD,20);
bif=new Font("sherif",Font.BOLD+Font.ITALIC,20);
tf.setFont(pf);

pb.addItemListener(new ListenerClass(pf));
itb.addItemListener(new ListenerClass(itf));
bb.addItemListener(new ListenerClass(bf));
bib.addItemListener(new ListenerClass(bif));
}

public class ListenerClass implements ItemListener {
private Font font;
public ListenerClass(Font f) {
font=f;
}
public void itemStateChanged(ItemEvent event) {
tf.setFont(font);
}
}

}


public class General {
public static void main(String[] args) {
Gui gobj=new Gui();
gobj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gobj.setSize(600,400);
gobj.setVisible(true);
}
}

Post a Reply

Replies

Oldest  Newest  Rating
+1 Jasmin Bakalović · February 22, 2015
You forgot to set layout:

setLayout(new FlowLayout());
  • 1

Java / Android Development

107,025 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator