
-----------------------------------
romantic_programmer
Thu Nov 01, 2007 3:55 pm

JApplet Problem
-----------------------------------
This isn't running.. so i was wondering if their is anything wrong with my code.


package AzureGale;

import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;


/**
 * @author Jeremy Poisson
 *
 */
public class MainFile extends JApplet {
	
	private JButton buttonOK;
	private JRadioButton small, medium, large;
	private JCheckBox pepperoni, mushrooms, greenPeppers;
	
	public void init(){
		this.setSize(3200,300);
		ButtonListener b1 = new ButtonListener();
		JPanel mainPanel = new JPanel();
		JPanel SizePanel = new JPanel();
		Border b1 = BorderFactory.createTitledBorder("Size");
		sizePanel.setBorder(b1);
		
		ButtonGroup sizeGroup = new ButtonGroup();
		small = new JRadioButton("Small");
		small.setSelected(true);
		sizePanel.add(small);
		sizeGroup.add(small);
		
		medium = new JRadioButton("medium");
		sizePanel.add(medium);
		sizeGroup.add(medium);
		
		large = new JRadioButton("large");
		sizePanel.add(large);
		sizeGroup.add(large);
		
		mainPanel.add(sizePanel);
		
		JPanel topPanel = new JPanel();
		Border b2 = 
			BorderFactory.createTitledBorder("Toppings");
		sizePanel.setBorder(b2);
		
		pepperoni = new JCheckBox("Pepperoni");
		topPanel.add(pepperoni);
		mushrooms = new JCheckBox("mushrooms");
		topPanel.add(mushrooms);
		greenPeppers = new JCheckBox("greenPeppers");
		topPanel.add(greenPeppers);
		
		mainPanel.add(topPanel);
		
		buttonOK = new JButton("OK");
		buttonOK.addActionListoner(b1);
		mainPanel.add(buttonOK);
		
		this.add(mainPanel);
		
		this.setVisible(true);
	}
	
	private class ButtonListener implements ActionListener {
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == buttonOK)
		{
			String tops = "";
			if (pepperoni.isSelected())
				tops += "Pepperoni\n";
			if (mushrooms.isSelected())
				tops += "Mushrooms\n";
			if (greenPeppers.isSelected())
				tops += "Green Peppers\n";
			String msg = "You ordered a ";
			if (small.isSelected())
				msg += "small pizza with ";
			if (medium.isSelected())
				msg += "medium pizza with ";
			if (large.isSelected())
				msg += "large pizza with ";
			
			if (tops.equals(""))
				msg += "no toppings.";
			else
				msg += "the following toppings:\n"
			+ tops;
			JOptionPane.showMessageDialog(buttonOK,
					msg, "Your Order",
					JOptionPane.INFORMATION_MESSAGE);
			
			pepperoni.setSelected(false);
			mushrooms.setSelected(false);
			greenPeppers.setSelected(false);
			small.setSelected(true);
		}	
	}
	}
}


here are my errors... 

Exception in thread "main" java.lang.NullPointerException
	at java.awt.Window.init(Unknown Source)
	at java.awt.Window.(Unknown Source)
	at java.awt.Frame.(Unknown Source)
	at java.awt.Frame.(Unknown Source)
	at sun.applet.AppletViewer.(Unknown Source)
	at sun.applet.StdAppletViewerFactory.createAppletViewer(Unknown Source)
	at sun.applet.AppletViewer.parse(Unknown Source)
	at sun.applet.AppletViewer.parse(Unknown Source)
	at sun.applet.Main.run(Unknown Source)
	at sun.applet.Main.main(Unknown Source)
	at sun.applet.AppletViewer.main(Unknown Source)


I am so confused... as well I am using Eclipse Platform

Version: 3.3.0

-----------------------------------
Barbarrosa
Thu Nov 01, 2007 9:43 pm

Re: JApplet Problem
-----------------------------------
I think you have to name ButtonListener or Border b1 something different.


        public void init(){
                this.setSize(3200,300);
                ButtonListener b1 = new ButtonListener();
                JPanel mainPanel = new JPanel();
                JPanel SizePanel = new JPanel();
                Border b1 = BorderFactory.createTitledBorder("Size");
                sizePanel.setBorder(b1); 


-----------------------------------
romantic_programmer
Thu Nov 01, 2007 9:53 pm

RE:JApplet Problem
-----------------------------------
Yes i figured that because it kept telling me  that it is a duplicate variable... 

but when i change ButtonListener it says the local variable is never read.

i am so confused...

to be honest that is my final issue that needs to be resolved.


here is my corrections so far... 


package AzureGale;

import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;


/**
 * @author Jeremy Poisson
 *
 */
public class MainFile extends JApplet {

	private static final long serialVersionUID = 1L;
	private JButton buttonOK;
	private JRadioButton small, medium, large;
	
	private JCheckBox pepperoni, mushrooms, greenPeppers;
	
	
	public void init()
	{
		this.setSize(320,300);
		
		ButtonListener b1 = new ButtonListener();
		
		JPanel mainPanel = new JPanel();
		
		JPanel SizePanel = new JPanel();
		
		Border b1 = 
			BorderFactory.createTitledBorder("Size");
		
		SizePanel.setBorder(b1);
		
		ButtonGroup sizeGroup = new ButtonGroup();
		
		small = new JRadioButton("Small");
		
		small.setSelected(true);
		
		SizePanel.add(small);
		
		sizeGroup.add(small);
		
		medium = new JRadioButton("medium");
		SizePanel.add(medium);
		sizeGroup.add(medium);
		
		large = new JRadioButton("large");
		SizePanel.add(large);
		sizeGroup.add(large);
		
		mainPanel.add(SizePanel);
		
		JPanel topPanel = new JPanel();
		Border b2 = 
			BorderFactory.createTitledBorder("Toppings");
		SizePanel.setBorder(b2);
		
		pepperoni = new JCheckBox("Pepperoni");
		topPanel.add(pepperoni);
		mushrooms = new JCheckBox("mushrooms");
		topPanel.add(mushrooms);
		greenPeppers = new JCheckBox("greenPeppers");
		topPanel.add(greenPeppers);
		
		mainPanel.add(topPanel);
		
		buttonOK = new JButton("OK");
		buttonOK.addActionListener((ActionListener) b1);
		mainPanel.add(buttonOK);
		
		this.add(mainPanel);
		
		this.setVisible(true);
	}
	
	private class ButtonListener implements ActionListener {
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == buttonOK)
		{
			String tops = "";
			if (pepperoni.isSelected())
				tops += "Pepperoni\n";
			if (mushrooms.isSelected())
				tops += "Mushrooms\n";
			if (greenPeppers.isSelected())
				tops += "Green Peppers\n";
			String msg = "You ordered a ";
			if (small.isSelected())
				msg += "small pizza with ";
			if (medium.isSelected())
				msg += "medium pizza with ";
			if (large.isSelected())
				msg += "large pizza with ";
			
			if (tops.equals(""))
				msg += "no toppings.";
			else
				msg += "the following toppings:\n"
			+ tops;
			JOptionPane.showMessageDialog(buttonOK,
					msg, "Your Order",
					JOptionPane.INFORMATION_MESSAGE);
			
			pepperoni.setSelected(false);
			mushrooms.setSelected(false);
			greenPeppers.setSelected(false);
			small.setSelected(true);
	     }	
	}
    }
}



-----------------------------------
chrisciscoioio
Fri Nov 02, 2007 8:07 am

Re: JApplet Problem
-----------------------------------
From what I have, you can see it in the question below.

You should user e.getSource() == 'Name of reference to object'

and then ethier set a class instance variable at the top to true or false, and return methods out of the privtae class, which should be doing no more than just flipping a switch and returning.

-----------------------------------
romantic_programmer
Sat Nov 03, 2007 12:59 pm

RE:JApplet Problem
-----------------------------------
but i do have that dont i?


public void actionPerformed(ActionEvent e) { 
                if (e.getSource() == buttonOK) 
                { 
                        String tops = ""; 
                        if (pepperoni.isSelected()) 
                                tops += "Pepperoni\n"; 
                        if (mushrooms.isSelected()) 
                                tops += "Mushrooms\n"; 
                        if (greenPeppers.isSelected()) 
                                tops += "Green Peppers\n"; 
                        String msg = "You ordered a "; 
                        if (small.isSelected()) 
                                msg += "small pizza with "; 
                        if (medium.isSelected()) 
                                msg += "medium pizza with "; 
                        if (large.isSelected()) 
                                msg += "large pizza with "; 
                        
                        if (tops.equals("")) 
                                msg += "no toppings."; 
                        else 
                                msg += "the following toppings:\n" 
                        + tops; 
                        JOptionPane.showMessageDialog(buttonOK, 
                                        msg, "Your Order", 
                                        JOptionPane.INFORMATION_MESSAGE); 
                        
                        pepperoni.setSelected(false); 
                        mushrooms.setSelected(false); 
                        greenPeppers.setSelected(false); 
                        small.setSelected(true); 
             }  


-----------------------------------
Barbarrosa
Tue Nov 06, 2007 11:58 pm

Re: JApplet Problem
-----------------------------------
You misspelled something:

buttonOK.addActionListoner(b1);

Should be spelled:

buttonOK.addActionListener(b1);

I actually have your program working. Should I post it?

-----------------------------------
romantic_programmer
Wed Nov 07, 2007 11:38 pm

RE:JApplet Problem
-----------------------------------
nah...   where did i spell it wrong?

as well j applets doesn't work at house... VISTA is being gay and not allowing me to access JApplets or anything involving ActiveX.
