Results 1 to 3 of 3
  1. #1
    JToolTip is offline Member
    Join Date
    Jul 2007
    Posts
    2
    Rep Power
    0

    Default Why isn't this showing?

    I don't see whats wrong with this code. It looks fine, but the applet on the website doesn't show the gui at all

    Java Code:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    import javax.swing.*;
    public class Client extends JApplet implements ActionListener
    {
       public void init()
       {
          setContentPane(new Client());
       }
       public static JMenuBar menuBar = new JMenuBar();
       public static JMenu file = new JMenu("File");
       public static JMenuItem home = new JMenuItem("Main Page");
       public static JPanel panel = new JPanel(new BorderLayout());
       public static JLabel intro = new JLabel("Welcome.");
       public Client() {
       	setLayout(new BorderLayout());
       	setJMenuBar(menuBar);
       			menuBar.add(file);
       					file.add(home);
       							home.addActionListener(this);
    	setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
       	panel.add(intro);
       }
       public void actionPerformed(ActionEvent e) {
       	Object s = e.getSource();
       	if(s == home) {
    	intro.setText("Once again, welcome!");
       	}
       }
    }

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    10

    Default

    I guess it will give you an exception if it does not show you anything. Try opening java console and see the exception.

  3. #3
    Heather is offline Senior Member
    Join Date
    Jun 2007
    Posts
    164
    Rep Power
    8

    Default

    I think that the problem is in init(), since Client() is a JApplet not Jframe

    I send you a code that works, analyze it
    Java Code:
    public class AppletTest extends JApplet {
    JFrame j = null;
    public void init() {
    j = new MyFrame();
    j.setVisible(true);
    }
    }
    
    class MyFrame extends JFrame implements ActionListener {
    public static JMenuBar menuBar = new JMenuBar();
    public static JMenu file = new JMenu("File");
    public static JMenuItem home = new JMenuItem("Main Page");
    public static JPanel panel = new JPanel(new BorderLayout());
    public static JLabel intro = new JLabel("Welcome.");
    
    public MyFrame() {
    setLayout(new BorderLayout());
    setJMenuBar(menuBar);
    menuBar.add(file);
    file.add(home);
    home.addActionListener(this);
    panel.add(intro);
    pack();
    }
    
    public void actionPerformed(ActionEvent e) {
    Object s = e.getSource();
    if (s == home) {
    intro.setText("Once again, welcome!");
    }
    }
    }

Similar Threads

  1. Need Help showing text in JTextArea
    By GuyFawkes in forum AWT / Swing
    Replies: 3
    Last Post: 05-05-2008, 09:19 AM
  2. Error Messages Not Showing Up
    By nvidia in forum Web Frameworks
    Replies: 0
    Last Post: 04-07-2008, 10:41 PM
  3. showing the servlets api docs in netbeans
    By truegilly in forum New To Java
    Replies: 0
    Last Post: 12-05-2007, 09:14 PM
  4. Assert - not showing any msg on console
    By ravian in forum New To Java
    Replies: 0
    Last Post: 11-16-2007, 03:20 PM
  5. Showing Images with J2ME
    By luisarca in forum CLDC and MIDP
    Replies: 0
    Last Post: 06-18-2007, 10:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •