Need Applet Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ALi Shaikh
    New Member
    • Sep 2007
    • 18

    Need Applet Help

    My applet which is supposed to display a Telephone Keypad wont display anyting
    Here is the Code, PLease Help
    The class:
    Code:
    //******************************************************
    // TelephonePanel.java
    //
    // Lays out a (functionless) GUI like a telephone keypad with a title.
    // Illustrates use of BorderLayout and GridLayout.
    //******************************************************
    import java.awt.*;
    import javax.swing.*;
    import java.awt.Container;
    import java.awt.GridLayout;
    
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    public class TelephonePanel extends JPanel
    {
    	  private JLabel label;
    public TelephonePanel()
    {
    	
    //set BorderLayout for this panel
    JPanel p = new JPanel(new BorderLayout());
    //create a JLabel with "Your Telephone" title
    label = new JLabel ("Your Telephone");
    //add title label to north of this panel
    p.add(label, BorderLayout.NORTH);
    //create panel to hold keypad and give it a 4x3 GridLayout
    JPanel keys = new JPanel(new GridLayout(3,4));
    //add buttons representing keys to key panel
    keys.add(new JButton("9"));
    keys.add(new JButton("8"));
    keys.add(new JButton("7"));
    keys.add(new JButton("6"));
    keys.add(new JButton("5"));
    keys.add(new JButton("4"));
    keys.add(new JButton("3"));
    keys.add(new JButton("2"));
    keys.add(new JButton("1"));
    keys.add(new JButton("#"));
    keys.add(new JButton("0"));
    keys.add(new JButton("*"));
    //add key panel to center of this panel
    p.add(keys, BorderLayout.CENTER);
    }
    }
    The Driver Program:
    Code:
    //******************************************************
    // Telephone.java
    //
    // Uses the TelephonePanel class to create a (functionless) GUI
    // like a telephone keypad with a title.
    // Illustrates use of BorderLayout and GridLayout.
    //******************************************************
    import javax.swing.*;
    public class Telephone
    {
    public static void main(String[] args)
    {
    JFrame frame = new JFrame("Telephone");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(new TelephonePanel());
    frame.pack();
    frame.setVisible(true);
    }
    }
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    You create a TelephonePanel which creates another panel p and another panel keys which is added to p but nothing is added to the TelephonePanel itself so nothing is in it and nothing will be displayed.

    Another thing: your code forms an application, not an applet.

    kind regards,

    Jos

    Comment

    Working...