Can anyone tell me why my Listener InstallListener is raising a NullPointerException when I press my okbutton? /* * Copyright ©. */
import java.io.*; import java.util.*; import javax.swing.*; import java.awt.event.*; import java.awt.Graphics; import java.awt.*; /** * @author cgregory */ public class SamsInstaller //implements Observer { JButton okbutton; JButton cnbutton; JButton openButton; JButton closebutton; JFrame installerFrame; JPanel installPanel; JPanel installContentPane; JPanel fcPanel; JPanel fcButtonPanel; JPanel buttonPanel; JTextArea log; JTextArea instructions; JFileChooser fc; InstallListener instlisnr; public SamsInstaller() { installerFrame = new JFrame("SAMS9 DIICOE Installer"); installContentPane = new JPanel(); installPanel = new JPanel(); okbutton = new JButton("OK"); cnbutton = new JButton("CANCEL"); JLabel introLabel = new JLabel("SAMS9 Database Installation \n" + "Space and Naval Warfare Systems Center Norfolk \n" + " (SPAWARSYSCEN) "); okbutton.addActionListener(new InstallListener()); cnbutton.addActionListener(new InstallListener()); installerFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); installPanel.setLayout(new GridBagLayout()); GridBagConstraints BagConstrnts = new GridBagConstraints(); buttonPanel = new JPanel(); buttonPanel.add(okbutton); buttonPanel.add(cnbutton); installPanel.setBorder(BorderFactory.createRaisedBevelBorder()); Insets myinset = new Insets(0,0,0,0); BagConstrnts.anchor = BagConstrnts.CENTER; BagConstrnts.insets = new Insets(0,10,0,0); BagConstrnts.gridx = 0; BagConstrnts.gridy = 0; BagConstrnts.gridwidth = 2; BagConstrnts.ipady = 40; installPanel.add(introLabel,BagConstrnts); BagConstrnts.gridx = 0; BagConstrnts.gridy = 4; BagConstrnts.ipady = 0; BagConstrnts.gridwidth = 0; installPanel.add(buttonPanel,BagConstrnts); installContentPane.setOpaque(true); installContentPane.add(installPanel); installerFrame.setContentPane(installContentPane); installerFrame.setSize(800,300); installerFrame.setVisible(true); } //public void update(Observable o, Object str) //{ //} public void startInstall() { //Create the log first, because the action listeners //need to refer to it. log = new JTextArea(5,20); log.setMargin(new Insets(5,5,5,5)); log.setEditable(false); JScrollPane logScrollPane = new JScrollPane(log); //Place instructions of what to do instructions = new JTextArea("Please select the directory were your Oracle " + "For example \"C:\\oracle\\oradata\\samsdb\"",5,30); instructions.setBackground(Color.lightGray); instructions.setLineWrap(true); JPanel instrPanel = new JPanel(); //Create a Label that will be invisible to create space //JLabel invisibleLabel = new JLabel(); //invisibleLabel.setVisible(false); //Create a file chooser fc = new JFileChooser(); fc.setDialogTitle("Select Data Directory"); //Uncomment one of the following lines to try a different //file selection mode. The first allows just directories //to be selected (and, at least in the Java look and feel, //shown). The second allows both files and directories //to be selected. If you leave these lines commented out, //then the default mode (FILES_ONLY) will be used. // fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); //fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); //Create the open button. We use the image from the JLF //Graphics Repository (but we extracted it from the jar). openButton = new JButton("Select a Directory"); openButton.addActionListener(new FileChooseLisnr()); fcPanel = new JPanel(new BorderLayout()); fcButtonPanel.setPreferredSize(new Dimension(300,150)); fcButtonPanel.add(openButton); //fcButtonPanel.add(invisibleLabel); fcButtonPanel.add(logScrollPane); fcButtonPanel.setLayout(new BoxLayout(fcButtonPanel,BoxLayout.Y_AXIS)); Dimension PaneDim = new Dimension(700,150); instrPanel.add(instructions); fcPanel.add(fcButtonPanel,BorderLayout.LINE_END); fcPanel.add(instrPanel, BorderLayout.CENTER); fcPanel.setMinimumSize(PaneDim); fcPanel.setPreferredSize(PaneDim); installContentPane.setPreferredSize(PaneDim); installContentPane.add(fcPanel); installerFrame.setSize(600,300); } public static void main(String[] args) { SamsInstaller installerInstance = new SamsInstaller(); } class FileChooseLisnr implements ActionListener { public void actionPerformed(ActionEvent event) { if (event.getSource() == openButton) { int returnVal = fc.showDialog(fcPanel, "Set Data Dir"); if (returnVal == JFileChooser.APPROVE_OPTION) { System.out.println(fc.getSelectedFile()); } } } } class InstallListener implements ActionListener { public void actionPerformed(ActionEvent event) { if (event.getSource().equals(cnbutton)) { System.exit(0); } else { installPanel.setVisible(false); startInstall(); } } } } _______________________________________________ Swing mailing list [EMAIL PROTECTED] http://eos.dk/mailman/listinfo/swing