3 Replies - 356 Views - Last Post: 27 December 2012 - 04:55 PM Rate Topic: -----

#1 zlloyd1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 13-December 12

Do not understand why the library is not working when imported

Posted 27 December 2012 - 01:41 PM

Here is my code:
package stilltryin;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class StillTryin{
frame();}
public void frame(){
JFrame f = new JFrame();
f.setVisible(true);
f.setSize(240,240);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
public static void main(String[] args){
StillTryin();}}

I am getting multiple errors about Class, Interface, or Enum expected from this code, but it makes no sense to me, :helpsmilie:/> because it seems to be focusing on the setSize, setVisible setDefaultCloseOperation,lines of my code, but I imported javax.swing.*; I am lost as to what is causing this, and it is becoming frustrating to me here. In any case, I have included an attachment with the errors I am getting in it. PLEASE HELP clear this up for me!! :surrender:/>

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Do not understand why the library is not working when imported

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2205
  • View blog
  • Posts: 5,239
  • Joined: 10-September 10

Re: Do not understand why the library is not working when imported

Posted 27 December 2012 - 01:50 PM

Your construction is pretty much all wrong. If you're just starting out, I recommend the standard HelloWorld tutorial to get an introduction to the basics of constructing a simple Java application.

I may not have preserved everything you intended in your code, but a correctly constructed ap built from what you posted looks like:
import javax.swing.JFrame;

public class StillTryin
{
    // method main calls the method frame()
    public static void main(String[] args)
    {
        frame();
        
    } // end method main()
    
    // method frame() builds a JFrame and makes it visible
    public static void frame()
    {
        JFrame f = new JFrame();
        f.setVisible(true);
        f.setSize(240,240);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
    } // end method frame()
}

This post has been edited by GregBrannon: 27 December 2012 - 02:04 PM

Was This Post Helpful? 1
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,904
  • Joined: 06-March 08

Re: Do not understand why the library is not working when imported

Posted 27 December 2012 - 03:28 PM

Indent your code properly and it will become obvious
Was This Post Helpful? 1
  • +
  • -

#4 zlloyd1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 13-December 12

Re: Do not understand why the library is not working when imported

Posted 27 December 2012 - 04:55 PM

View PostGregBrannon, on 27 December 2012 - 01:50 PM, said:

Your construction is pretty much all wrong. If you're just starting out, I recommend the standard HelloWorld tutorial to get an introduction to the basics of constructing a simple Java application.

I may not have preserved everything you intended in your code, but a correctly constructed ap built from what you posted looks like:
import javax.swing.JFrame;

public class StillTryin
{
    // method main calls the method frame()
    public static void main(String[] args)
    {
        frame();
        
    } // end method main()
    
    // method frame() builds a JFrame and makes it visible
    public static void frame()
    {
        JFrame f = new JFrame();
        f.setVisible(true);
        f.setSize(240,240);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
    } // end method frame()
}

THANK YOU A MILLION YO!! :genius:/>

View Postpbl, on 27 December 2012 - 03:28 PM, said:

Indent your code properly and it will become obvious


Thanks for the advice, like I said I am completely noob to Java, and anything helps!! :bananaman:/>
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1