DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: what is missing, please help

  1. #1
    Join Date
    Jun 2010
    Posts
    11

    Question what is missing, please help

    trying to create an applet, here is the code:

    Code:
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import com.sun.java.swing.*;
    import java.net.*;
    import java.io.*;
    
    //import com.sun.java.swing.UIManager;
    public class OrderStatusApplet extends JApplet {
    
    	boolean isStandalone = false;
    	JPanel jStatusPanel = new JPanel();
    	JPanel jActionPanel = new JPanel();
    	GridLayout gridLayout1 = new GridLayout(1, 2);
    	JButton jGetStatusButton = new JButton();
    	JTextField jOrderTextField = new JTextField();
    	JLabel jLabel1 = new JLabel();
    	JTextArea jStatusResultTextArea = new JTextArea();
    	
    	//get a parameter value
    	public String getParameter(String key, String def) {
    		
    		return isStandalone ? System.getProperty(key, def) :
    			(getParameter(key) != null ? getParameter(key) : def);
    			
    	}
    	
    	//default construct
    	public OrderStatusApplet() {
    	
    	}
    	
    	//initialize the applet
    	public void init() {
    	
    		try {
    			jbInit();
    		}
    		catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    	
    	//component initialization
    	private void jbInit() throws Exception {
    	
    		this.setSize(400,150);
    		this.getContentPane().setLayout(gridLayout1);
    		jGetStatusButton.setText("Get Status");
    		jGetStatusButton.addActionListener(
    			new java.awt.event.ActionListener() {
    				public void actionPerformed(ActionEvent e) {
    					jGetStatusButton_actionPerformed(e);
    				}
    		});
    		jLabel1.setText("Order #");
    		jOrderTextField.setPreferredSize(new Dimension(50, 19));
    		jStatusResultTextArea.setPreferredSize( new Dimension(175, 135));
    		this.getContentPane().add(jActionPanel, null);
    		jActionPanel.add(jLabel1, null);
    		jActionPanel.add(jOrderTextField, null);
    		jActionPanel.add(jGetStatusButton, null);
    		this.getContentPane().add(jStatusPanel, null);
    		jStatusPanel.add(jStatusResultTextArea, null);
    	}
    	
    	//Get Applet information
    	public String getAppletInfo() {
    		return "Applet Information";
    	}
    	
    	//Get parameter info
    	public String[][] getParameterInfo() {
    		return null;
    	}
    	
    	//write the StudentList to the Connection
    	public void writeOrder(URLConnection connection, Order value) {
    		try {
    			//set this to false in order to ignore caching
    			connection.setUseCaches(false);
    			
    			//set the content-type of the request
    			//application/octet-stream is used when writing
    			//application specific byte size data
    			connection.setRequestProperty("CONTENT_TYPE", "application/octet-stream");
    			
    			//set these values to true to use the same connection
    			//for both input and output
    			connection.setDoInput(true);
    			connection.setDoOutput(true);
    			
    			//create the ObjectOutputStream passing it the 
    			//ByteArrayOutputStream object.
    			ObjectOutputStream os = new ObjectOutputStream(connection.getOutputStream());
    			
    			//write the studentlist to the objectoutputstream
    			System.err.println("Writing Order Object.");
    			os.writeObject(value);
    			os.flush();
    			os.close();
    		}
    		catch (IOException e) {
    			System.err.println(e.getMessage());
    		}
    	}
    	
    	public Order readOrder(URLConnection connection) {
    
    		Order order = null;
    		
    		try {
    			//create the objectinputstream passing it the 
    			//inputstream object from the URLConnection
    			ObjectInputStream is = new ObjectInputStream(connection.getInputStream());
    			
    			System.err.println("Waiting for response.");
    			//read the stored object and downcast it back to
    			//a Order
    			order = (Order)is.readObject();
    			is.close();
    		}
    		catch (IOException e) {
    			System.err.println(e.getMessage());
    		}
    		catch (ClassNotFoundException ce) {
    			System.err.println(ce.getMessage());
    		}
    		return order;
    	}
    	
    	void jGetStatusButton_actionPerformed(ActionEvent event) {
    	
    		try {
    			//this is where the OrderStatus Transaction begins
    			Order order = new Order();
    			
    			order.setOrder(jOrderTextField.getText());
    			
    			//create our url
    			URL url = new URL("http://localhost:8080/orderApp/OrderStatusServlet");
    			
    			//open out urlconnection
    			System.err.println("Opening Connection.");
    			URLConnection con = url.openConnection();
    			
    			//write the order
    			writeOrder(con, order);
    			
    			//get the order from the response,
    			//after the status has been checked, and printed out.
    			Order response_order = readOrder(con);
    			if (response_order != null) {
    				//put the status String returned from the 
    				//OrderStatusServlet into the jTextArea Object
    				jStatusResultTextArea.setText(response_order.getStatus());
    			}
    			else {
    				System.err.println("readObject failed.");
    			}
    		}
    		catch (MalformedURLException mue) {
    			System.err.println(mue.getMessage());
    		}
    		catch (Exception e) {
    			System.err.println(e.getMessage());
    		}
    	}
    }
    and here is the errors.....

    OrderStatusApplet.java:9: cannot find symbol
    symbol: class JApplet
    public class OrderStatusApplet extends JApplet {
    ^
    OrderStatusApplet.java:12: cannot find symbol
    symbol : class JPanel
    location: class OrderStatusApplet
    JPanel jStatusPanel = new JPanel();
    ^
    OrderStatusApplet.java:13: cannot find symbol
    symbol : class JPanel
    location: class OrderStatusApplet
    JPanel jActionPanel = new JPanel();
    ^
    OrderStatusApplet.java:15: cannot find symbol
    symbol : class JButton
    location: class OrderStatusApplet
    JButton jGetStatusButton = new JButton();
    ^
    OrderStatusApplet.java:16: cannot find symbol
    symbol : class JTextField
    location: class OrderStatusApplet
    JTextField jOrderTextField = new JTextField();
    ^
    OrderStatusApplet.java:17: cannot find symbol
    symbol : class JLabel
    location: class OrderStatusApplet
    JLabel jLabel1 = new JLabel();
    ^
    OrderStatusApplet.java:18: cannot find symbol
    symbol : class JTextArea
    location: class OrderStatusApplet
    JTextArea jStatusResultTextArea = new JTextArea();
    thanks mike.....

  2. #2
    Join Date
    Jul 2005
    Location
    SW MO, USA
    Posts
    299
    You need to look in the API doc and see what package(s) the missing classes are defined in.
    Then add an import statement for them at the beginning of your code.

  3. #3
    Join Date
    Mar 2005
    Location
    UK, London
    Posts
    150
    The j.. componenets are part of the swing package

    import javax.swing.*;

  4. #4
    Join Date
    Jun 2010
    Posts
    11

    Question thanks

    so the :

    import com.sun.java.swing.*;

    don't import the swing package?

    i dont mean to sound dumb but i am new to java and trying to learn.....

    thanks for the help, mike

  5. #5
    Join Date
    May 2004
    Posts
    40
    Check out Swing Package Names

    Most of the Swing package names starting with com.sun.java.swing are old names that were replaced with the javax.swing package names. This happened in the JDK 1.2 timeframe, so it's been that way for a while.

    I know you are using Bluefish, have you considered installing and using Eclipse or NetBeans? Both are free and both will help you get your imports right.

  6. #6
    Join Date
    Jun 2010
    Posts
    11

    Exclamation will check....

    thanks for the info, the book i found is kinda old as well, going this weekend to try to find something a little newer, will check out the packages and the IDE s as well,

    thanks, mike....

Similar Threads

  1. Replies: 2
    Last Post: 05-14-2009, 09:22 AM
  2. MS Word from ASP.NET
    By michurin in forum ASP.NET
    Replies: 0
    Last Post: 07-10-2007, 11:21 AM
  3. Missing bytes with JAVA SAX Parser
    By vrkanth2 in forum Java
    Replies: 1
    Last Post: 11-09-2006, 02:00 PM
  4. Missing HTML/Javascript
    By ravigandhi in forum Web
    Replies: 0
    Last Post: 08-08-2006, 03:31 PM
  5. ASP.NET 2.0 -- Code not executing
    By lagyossarian in forum ASP.NET
    Replies: 0
    Last Post: 04-20-2006, 02:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center