i don't know what happened, but i was running an applet that i made on a webpage and it works fine. i have the latest JRE and i am running firefox 4. then i've made some changes to the applet, tested it, it works, and copy and paste the class file to my html folder. i open up the webpage with the applet and it's a white blank. i've tested it on 3 browsers (opera, firefox, and chrome) and it all shows the same result. i have no idea what is wrong b/c it worked before and now it doesn't work...

it's a silly little program, but can somebody test this out for me, and let me know if it works on your browser.

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.text.DecimalFormat;

public class PlaceOrder extends JApplet{
	
	private JPanel blank;
	private JPanel blank2;
	private JPanel blank3;
   private JPanel blank4;
	private JPanel blank5;
	private JPanel title; 
	private JPanel quantity; 
	private JPanel item1;
	private JPanel item2;
	private JPanel item3;
	private JPanel button;
	private JPanel taco;
	private JPanel cake;
	private JPanel fish;
	private JPanel total;
	private JTextField qty1;
	private JTextField qty2;
	private JTextField qty3;
	private JTextField totalField;
	private JTextField totalTime;
	private JPanel name;
	
	public void init(){
		buildBlank();
		buildBlank2();
		buildBlank3();
		buildBlank4();
		buildBlank5();
		buildTitle();
		buildQuantity();
		buildItem1();
		buildItem2();
		buildItem3();
		buildField1();
		buildField2();
		buildField3();
		buildTotal();
		buildButton();
		buildName();
		setLayout(new GridLayout(8,2));
		
		add(title);
		add(blank2);
		add(name);
		add(blank);
		add(blank5);
		add(quantity);
		add(item1);
		add(taco);
		add(item2);
		add(cake);
		add(item3);
		add(fish);
		add(blank3);
		add(total);
		add(blank4);
		add(button);
	}
	private void buildName(){
		name = new JPanel();
		JLabel name1 = new JLabel("name: ");
		JTextField name2 = new JTextField(10);
		name.setLayout(new FlowLayout(FlowLayout.LEFT));
		name.add(name1);
		name.add(name2);
	}
	private void buildBlank(){
		blank = new JPanel();
		blank.setLayout(new FlowLayout(FlowLayout.LEFT));
	}
	private void buildBlank2(){
		blank2 = new JPanel();
		blank2.setLayout(new FlowLayout(FlowLayout.RIGHT));
	}
	private void buildBlank3(){
		blank3 = new JPanel();
		blank3.setLayout(new FlowLayout(FlowLayout.LEFT));
	}
	private void buildBlank4(){
		blank4 = new JPanel();
		blank4.setLayout(new FlowLayout(FlowLayout.LEFT));
	}
	private void buildBlank5(){
		blank5 = new JPanel();
		blank5.setLayout(new FlowLayout(FlowLayout.LEFT));
	}


	private void buildTitle(){
		title = new JPanel();
		JLabel message11 = new JLabel("The Anxious Clown ***");
		JLabel message1 = new JLabel("Take Out / Place Order: ");
		title.setLayout(new FlowLayout(FlowLayout.LEFT));
		title.add(message11);
		title.add(message1);
	}
	private void buildQuantity(){
		quantity = new JPanel();
		JLabel message2 = new JLabel("QTY");
		quantity.setLayout(new FlowLayout(FlowLayout.CENTER));
		quantity.add(message2); 
	}
	private void buildItem1(){
		item1 = new JPanel();
		JLabel message3 = new JLabel("skirt steak taco: ");
		item1.setLayout(new FlowLayout(FlowLayout.LEFT));
		item1.add(message3);
	}
	private void buildItem2(){
		item2 = new JPanel();
		JLabel message4 = new JLabel("ice cream cake: ");
		item2.setLayout(new FlowLayout(FlowLayout.LEFT));
		item2.add(message4);

	}
	private void buildItem3(){
		item3 = new JPanel();
		JLabel message5 = new JLabel("fish and chips: ");
		item3.setLayout(new FlowLayout(FlowLayout.LEFT));
		item3.add(message5);

	}
	private void buildField1(){//taco
		taco = new JPanel();
		qty1 = new JTextField(5);
		qty1.setText("0");
		qty1.setLayout(new FlowLayout(FlowLayout.RIGHT));
		taco.add(qty1);	
	}
	private void buildField2(){//cake
		cake = new JPanel();
		qty2 = new JTextField(5);
		qty2.setText("0");
		qty2.setLayout(new FlowLayout(FlowLayout.RIGHT));
		cake.add(qty2);
	}
	private void buildField3(){//fish
		fish = new JPanel();
		qty3 = new JTextField(5);
		qty3.setText("0");
		qty3.setLayout(new FlowLayout(FlowLayout.RIGHT));
		fish.add(qty3);
	}
	private void buildTotal(){
		total = new JPanel();
		JLabel totalMessage = new JLabel("Total: $");
		JLabel timeMessage = new JLabel("Food is ready in: ");
		totalField = new JTextField(5);
		totalTime = new JTextField(7);
		total.setLayout(new FlowLayout(FlowLayout.CENTER));
		total.add(totalMessage);
		total.add(totalField); 
		total.add(timeMessage);
		total.add(totalTime);
	}
	private void buildButton(){
		button = new JPanel();
		JButton totalButton = new JButton("Place Order! ");
		totalButton.addActionListener(new ButtonListener());
		totalButton.setLayout(new FlowLayout(FlowLayout.RIGHT));
		button.add(totalButton);
	}
	private class ButtonListener implements ActionListener{
		public void actionPerformed(ActionEvent e){
			int numTaco, numCake, numFish;
			numTaco = Integer.parseInt(qty1.getText());
			numCake = Integer.parseInt(qty2.getText());
			numFish = Integer.parseInt(qty3.getText());
			DecimalFormat formatter = new DecimalFormat("0.00");
			double totalAmount = (numTaco * 1.99) + (numCake * 3.99) + (numFish * 4.99);
			totalField.setText(formatter.format(totalAmount));
			totalTime.setText("30 mintues");
			
		}
	}
	
	
	
	
}

html code

<html>
	<head>
		<title>Place Order / The Anxious Clown</title>
		<style type="text/css">
			body{
				background-color: #F0F0F0;
				margin-left: 20%;
				margin-right: 20%;
				border: 2px dotted gray;
				padding: 20px 20px 20px 20px;
				font-family: sans-serif;
		</style>
	</head>
	<body>
		<applet code = "PlaceOrder.class" width = 500 height = 575></applet>
		
		<br>
		
		<a href = "index.html">back to homepage</a>
	</body>
	
	
</html>

Recommended Answers

All 2 Replies

you've created all the items but not added any of them to the container...

thats why nothing is shown... use

add(<<somecomponent);

you are adding textfields, buttons to panels, you need to add the panel to the main container...

can you please elaborate on that because it works fine when i use applet viewer.

update: there's something fundamentally wrong with my code, here's a simple applet i've wrote that a little circle follows your mouse everywhere.

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;


public class Eyes2 extends JApplet{
	
	private int x2 = 198;
	private int y2 = 199;
	private int width2 = 15;
	private int height2 = 15; 
	
	public void init(){
		getContentPane().setBackground(Color.black);
	}
	
	public void paint(Graphics g){
		super.paint(g);
		
		g.setColor(Color.white);
		
		g.fillOval(x2, y2, width2, height2);
		 addMouseListener(new MyMouseListener());

		addMouseMotionListener(new MyMouseMotionListener());

	}
	private class MyMouseListener
                         implements MouseListener
   {
      public void mousePressed(MouseEvent e)
      {
              }

      public void mouseClicked(MouseEvent e)
      {
               
      }

      public void mouseReleased(MouseEvent e)
      {
               }

      public void mouseEntered(MouseEvent e)
      {
			x2 = 198;
			 y2 = 199;
			 repaint(); 
      }

      public void mouseExited(MouseEvent e)
      {
                        x2 = 198;
			 y2 = 199;
			 repaint();           
		}
   }

	   
   private class MyMouseMotionListener
                         implements MouseMotionListener
   {
      public void mouseDragged(MouseEvent e)
      {
      }

      public void mouseMoved(MouseEvent e)
      {
      	          x2 = e.getX();
			y2 = e.getY();	
			
			repaint();
      }
		
		
   }

	
	
	
	
}

when i run this, the circle does not move at all. however this works fine in an applet viewer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.