Results 1 to 3 of 3
Thread: Why isn't this showing?
- 07-05-2007, 06:24 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 2
- Rep Power
- 0
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!"); } } }
- 07-05-2007, 06:53 PM #2
I guess it will give you an exception if it does not show you anything. Try opening java console and see the exception.
- 07-07-2007, 11:54 PM #3
Senior Member
- Join Date
- Jun 2007
- Posts
- 164
- Rep Power
- 6
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
-
Need Help showing text in JTextArea
By GuyFawkes in forum AWT / SwingReplies: 3Last Post: 05-05-2008, 09:19 AM -
Error Messages Not Showing Up
By nvidia in forum Web FrameworksReplies: 0Last Post: 04-07-2008, 10:41 PM -
showing the servlets api docs in netbeans
By truegilly in forum New To JavaReplies: 0Last Post: 12-05-2007, 09:14 PM -
Assert - not showing any msg on console
By ravian in forum New To JavaReplies: 0Last Post: 11-16-2007, 03:20 PM -
Showing Images with J2ME
By luisarca in forum CLDC and MIDPReplies: 0Last Post: 06-18-2007, 10:39 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks