• Post Reply Bookmark Topic Watch Topic
  • New Topic

No error But result not shown

 
gparan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class menu1 extends JPanel implements ActionListener
{
public JTextArea aa;
public void fnew()
{
aa = new JTextArea(40,30);
add(aa);
}
public menu1(JFrame f)
{
JPanel p;
JMenuBar bar = new JMenuBar();
JMenu file= new JMenu("file");
JMenuItem newf = new JMenuItem("new");
aa = new JTextArea();
newf.addActionListener(this);
bar.add(file);
file.add(newf);
f.setJMenuBar(bar);
}
public static void main(String args[])
{
JFrame frame = new JFrame("hello");
menu1 m = new menu1(frame);
frame.getContentPane().add(m,"Center");
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String ss;
ss=e.getActionCommand();
if(ss.equals("new"))
fnew();
}
}
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by gparan:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class menu1 extends JPanel implements ActionListener
{
public JTextArea aa;
public void fnew()
{
aa = new JTextArea(40,30);
add(aa);
}
public menu1(JFrame f)
{
JPanel p;
JMenuBar bar = new JMenuBar();
JMenu file= new JMenu("file");
JMenuItem newf = new JMenuItem("new");
aa = new JTextArea();
newf.addActionListener(this);
bar.add(file);
file.add(newf);
f.setJMenuBar(bar);
}
public static void main(String args[])
{
JFrame frame = new JFrame("hello");
menu1 m = new menu1(frame);
frame.getContentPane().add(m,"Center");
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String ss;
ss=e.getActionCommand();
if(ss.equals("new"))
fnew();
}
}

Remember the default size for a frame/jframe is ... 0,0
add frame.setSize(300,300);
before frame.setVisible(true);
You'll see it then.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!