Results 1 to 4 of 4
  1. #1
    Latha.P is offline Member
    Join Date
    Nov 2015
    Posts
    1
    Rep Power
    0

    Default Java Swing : JFrame, JPanel, JButton cannot be resolved to a type.

    Hi,
    I am new to Java Swings and trying this simple program in eclipse. please help me to run this simple program.

    import javax.swing.*;
    public class HelloWorldFrame extends JFrame {



    public static void main(String[] args) {

    final JFrame frame = new JFrame();
    JPanel panel = new JPanel();

    JButton button1 = new JButton();

    frame.add(panel);
    panel.add(button1);
    frame.setVisible(true);

    button1.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent arg0) {
    JOptionPane.showMessageDialog(frame.getComponent(0 ), "Hello World");

    }
    });

    }

    }

    Do i need to add jars externally or what needs to be done to run this? please help me.

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    878
    Rep Power
    12

    Default Re: Java Swing : JFrame, JPanel, JButton cannot be resolved to a type.

    Ramya:cool:

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Java Swing : JFrame, JPanel, JButton cannot be resolved to a type.

    First type Ctrl-Shift-O and let Eclipse organize your imports ...

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  4. #4
    abenmariem is offline Member
    Join Date
    Nov 2015
    Location
    USA
    Posts
    1
    Rep Power
    0

    Default Re: Java Swing : JFrame, JPanel, JButton cannot be resolved to a type.

    Quote Originally Posted by Latha.P View Post
    Hi,
    I am new to Java Swings and trying this simple program in eclipse. please help me to run this simple program.

    import javax.swing.*;
    public class HelloWorldFrame extends JFrame {



    public static void main(String[] args) {

    final JFrame frame = new JFrame();
    JPanel panel = new JPanel();

    JButton button1 = new JButton();

    frame.add(panel);
    panel.add(button1);
    frame.setVisible(true);

    button1.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent arg0) {
    JOptionPane.showMessageDialog(frame.getComponent(0 ), "Hello World");

    }
    });

    }

    }

    Do i need to add jars externally or what needs to be done to run this? please help me.
    JFrame, JButton and JPanel are built in the JDK.
    You don't need to add any JAR to your project.
    You need only to add the necessary imports:
    import javax.swing.JFrame;
    import javax.swing.JButton;
    import javax.swing.JPanel;

Similar Threads

  1. JPanel-type class doesn't apear on the JFrame?
    By AvivC in forum New To Java
    Replies: 3
    Last Post: 12-29-2013, 12:09 PM
  2. Cannot be resolved to a type
    By Naxix in forum AWT / Swing
    Replies: 1
    Last Post: 03-18-2012, 12:16 PM
  3. [SWING]Adding JButton(class1) to JPanel(class2)
    By equal in forum New To Java
    Replies: 8
    Last Post: 02-20-2011, 01:09 AM
  4. JFrame+JPanel+JButton+JtextArea+ImageIcon
    By zusss in forum AWT / Swing
    Replies: 11
    Last Post: 02-18-2011, 10:40 AM
  5. Replies: 4
    Last Post: 12-13-2010, 10:00 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
  •