Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: GUI errors

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default GUI errors

    I have been trying to figure out these errors and I am stuck. You guys are good at seeing what I can not, thanks!

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
     
    public class GUIWindow extends JFrame{
     
    	//private Circle circ = new Circle();
     
    private JLabel radiusLabel            = new JLabel("Radius");
    private JLabel areaLabel              = new JLabel("Area");
    private TextField radiusField          = new JTextField("3.14");
    private TextField areaField            = new JTextField("0.0");
    private JButton radButton             = new JButton("Convert >>>");
     
     public GUIWindow(){
       JPanel dataPanel = new JPanel(new GridLayout(2,2,12,6));
       dataPanel.add(radiusLabel);
       dataPanel.add(areaLabel);
       dataPanel.add(radiusField);
       dataPanel.add(areaField);
       JPanel buttonPanel                  = new JPanel();
       buttonPanel.add(radButton);
       Container container = getContentPane();
       container.add(dataPanel, BorderLayout.CENTER);
       container.add(buttonPanel, BorderLayout.SOUTH);
     
       radButton.addActionListener(new RadiusListener());
     }
     
     private class RadiusListener implements ActionListener{
        public void actionPerformed(ActionEvent e){
     
           String input = radiusField.getText();
           double rad = Double.parseDouble(input);
           rad.setRadius(rad);
           double area = rad.getArea();
           areaField.setText("" + area);
           }
           }
           }

    the errors:

    E:\JavaCh8SR\ConvertWithGUI.java:10: cannot find symbol
    symbol : method setVisable(boolean)
    location: class GUIWindow
    theGUI.setVisable(true);
    ^
    .\GUIWindow.java:11: incompatible types
    found : javax.swing.JTextField
    required: java.awt.TextField
    private TextField radiusField = new JTextField("3.14");
    ^
    .\GUIWindow.java:12: incompatible types
    found : javax.swing.JTextField
    required: java.awt.TextField
    private TextField areaField = new JTextField("0.0");
    ^
    .\GUIWindow.java:35: double cannot be dereferenced
    rad.setRadius(rad);
    ^
    .\GUIWindow.java:36: double cannot be dereferenced
    double area = rad.getArea();
    ^


    and the main:
    import javax.swing.*;
     
    public class ConvertWithGUI{
     
    public static void main(String[] args){
    GUIWindow theGUI = new GUIWindow();
    theGUI.setTitle("Radius Converter");
    theGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    theGUI.pack();
    theGUI.setVisable(true);
    }
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: GUI errors

    Those exceptions tell you what's wrong.

    In the first one, your variable theGUI (or the instance it references) does not have a setVisable() method. Did you perhaps mean setVisible()?
    In both the incompatible types, you're just trying to use the wrong kind of variable to store the instance.
    And double is a primitive, not an Object. So it doesn't contain any methods.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Many Errors
    By Woody619 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: July 16th, 2010, 09:36 PM
  2. Getting errors
    By Nonire in forum What's Wrong With My Code?
    Replies: 7
    Last Post: July 4th, 2010, 12:21 PM
  3. Why am I getting 62 errors?
    By DestinyChick1225 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 1st, 2010, 04:41 AM
  4. not spelling errors
    By britishgoose01 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 28th, 2010, 08:59 PM
  5. Ambiguity and non-static variable reference error in java
    By jenseits in forum AWT / Java Swing
    Replies: 5
    Last Post: December 8th, 2008, 07:04 PM