Re: Help with my first Java program
- From: Donkey Hot <spam@xxxxxxxxxxxxxxxxx>
- Date: 27 Dec 2007 14:06:30 GMT
mohed.haidar@xxxxxxxxx wrote in news:05e9ea93-a409-4198-8b38-13b6d587cb61
@v4g2000hsf.googlegroups.com:
Hello guys. I just wrote my first java program and i have a couple of
questions and a problem. I would be glad if someone can give me a
hand.
The questions :
1. How do i pack everything into i nice executable file for others
to run without the need to open a cmd prompt and typing java ... and
so on ?
2. How do you guys do when your looking for a command. Is there some
kind of registry online, or do you have books or do you just know it
all from the getgo :) ?
The problem is that, while the compailer doesn't complain, i still get
an error at runtime. The error staits
Exception in thread "main" java.lang.NullPointerException
at DiveLog.DiveLog.populateMettoMenu(DiveLog.java:76)
at DiveLog.DiveLog.<init>(DiveLog.java:38)
at DiveLog.DiveLog.main(DiveLog.java:15)
Press any key to continue . . .
and i cant get the program running.
The source looks like this
package DiveLog;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Metto
{
private JFrame mettoFrame;
private JTabbedPane mettoPane;
public static void main(String[] args)
{
Metto go = new Metto();
}
public Metto()
{
JFrame mettoFrame = new JFrame("Metto ligger långt efter");
mettoFrame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
mettoPane = new JTabbedPane(SwingConstants.RIGHT);
mettoPane.setBackground(Color.blue);
mettoPane.setForeground(Color.white);
populateMettoPane();
populateMettoMenu();
mettoFrame.getContentPane().add(mettoPane);
mettoFrame.pack();
mettoFrame.setSize(750, 650);
mettoFrame.setBackground(Color.white);
mettoFrame.setVisible(true);
}
private void populateMettoPane()
{
mettoPane.addTab("Tryck här",
null,
new press1(),
"Det här va inte så svårt");
mettoPane.addTab("Eller här",
null,
new press2(),
"Inte det här häller");
}
private void populateMettoMenu()
{
JMenuBar mb = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item = new JMenuItem("Exit");
item.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
menu.add(item);
mb.add(menu);
mettoFrame.setJMenuBar(mb);
}
public class press1 extends JPanel
{
}
public class press2 extends JPanel
{
}
}
Thx in advance for any help you guys can give me. Mohamed Haidar.
You have declared variable "mettoFrame" twice, once as a property in
class, and then a local variable in the constructor Metto(). You do not
create the class member mettoFrame, but try to use it in
populateMettoMenu().
Netbeans IDE told this as soon as loaded the source in it.
.
- References:
- Help with my first Java program
- From: mohed . haidar
- Help with my first Java program
- Prev by Date: Help with my first Java program
- Next by Date: Re: Help with my first Java program
- Previous by thread: Help with my first Java program
- Next by thread: Re: Help with my first Java program
- Index(es):
Relevant Pages
|