Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #20054 > unrolled thread

JFrame issues

Started byK <kalezwe@gmail.com>
First post2012-12-02 20:34 -0800
Last post2012-12-03 22:51 -0500
Articles 4 — 4 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  JFrame issues K <kalezwe@gmail.com> - 2012-12-02 20:34 -0800
    Re: JFrame issues Lew <lewbloch@gmail.com> - 2012-12-02 21:12 -0800
    Re: JFrame issues Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-03 08:34 -0500
    Re: JFrame issues Arne Vajhøj <arne@vajhoej.dk> - 2012-12-03 22:51 -0500

#20054 — JFrame issues

FromK <kalezwe@gmail.com>
Date2012-12-02 20:34 -0800
SubjectJFrame issues
Message-ID<511a3304-a598-413b-a630-b2e1454fd11c@googlegroups.com>
Here is my script does anyone know why this isn't working

import javax.swing.JFrame;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.Continer;

class Jframe {

	public static void main(String[] args) {
		JFrame frame = new JFrame();
		ImageIcon icon = new ImageIcon(puffin.jpg);
		JLabel label = new JLable (icon);
		Container contentPane = frame.getContentPane();
		
		contentPane.add(label);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);

	}

}

[toc] | [next] | [standalone]


#20055

FromLew <lewbloch@gmail.com>
Date2012-12-02 21:12 -0800
Message-ID<07cd0b03-3086-4ae5-8046-ee77d4900d37@googlegroups.com>
In reply to#20054
K wrote:
> Here is my script

It's not a script.

>  does anyone know why this isn't working

What is "working" for this program?

What happens instead? 

Copy and paste your error messages so we don't have to 
tire out our crystal balls.

You should place your program in a package, rather than the 
"default" (empty) package.

> import javax.swing.JFrame;
> import javax.swing.ImageIcon;
> import javax.swing.JLabel;
> import javax.swing.Continer;
   ^
You should get a compilation error on this import.

> class Jframe {

Get in the habit of declaring classes 'public', and not naming them so 
similarly to standard API types.

> 	public static void main(String[] args) {
> 		JFrame frame = new JFrame();

You failed to put the GUI work on the Event Dispatch Thread (EDT).

> 		ImageIcon icon = new ImageIcon(puffin.jpg);
                                                                    ^
This line should raise a compilation error.

> 		JLabel label = new JLable (icon);
                                             ^
This line should raise a compilation error.

> 		Container contentPane = frame.getContentPane();
> 		contentPane.add(label);
> 		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> 		frame.pack();
> 		frame.setVisible(true);
> 	}
> }

You are getting compilation errors that tell you exactly where you are being 
careless.

Use 'invokeLater()' to do GUI things (like defining your frame and all that).
Doing GUI off the EDT and doing non-GUI on the EDT are the twin sins of Swing.

Repent your sins.

-- 
Lew

[toc] | [prev] | [next] | [standalone]


#20064

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2012-12-03 08:34 -0500
Message-ID<k9i9pp$jfd$1@dont-email.me>
In reply to#20054
On 12/2/2012 11:34 PM, K wrote:
> Here is my script does anyone know why this isn't working
>
> import javax.swing.JFrame;
> import javax.swing.ImageIcon;
> import javax.swing.JLabel;
> import javax.swing.Continer;

     Because there's no Continer class in javax.swing.

> class Jframe {
>
> 	public static void main(String[] args) {
> 		JFrame frame = new JFrame();

     Because Swing components should be constructed and
manipulated on the Event Dispatch Thread.

> 		ImageIcon icon = new ImageIcon(puffin.jpg);

     Because puffin.jpg is a syntax error.

> 		JLabel label = new JLable (icon);

     Because no JLable class has been declared.

> 		Container contentPane = frame.getContentPane();

     Because no Container class has been declared.

> 		contentPane.add(label);
> 		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> 		frame.pack();
> 		frame.setVisible(true);
>
> 	}
>
> }

-- 
Eric Sosman
esosman@comcast-dot-net.invalid

[toc] | [prev] | [next] | [standalone]


#20084

FromArne Vajhøj <arne@vajhoej.dk>
Date2012-12-03 22:51 -0500
Message-ID<50bd7345$0$287$14726298@news.sunsite.dk>
In reply to#20054
On 12/2/2012 11:34 PM, K wrote:
> Here is my script does anyone know why this isn't working
>
> import javax.swing.JFrame;
> import javax.swing.ImageIcon;
> import javax.swing.JLabel;
> import javax.swing.Continer;
>
> class Jframe {
>
> 	public static void main(String[] args) {
> 		JFrame frame = new JFrame();
> 		ImageIcon icon = new ImageIcon(puffin.jpg);
> 		JLabel label = new JLable (icon);
> 		Container contentPane = frame.getContentPane();
> 		
> 		contentPane.add(label);
> 		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> 		frame.pack();
> 		frame.setVisible(true);
>
> 	}
>
> }

You need to learn to look at the error messages and fix
bugs following the information in those.

Then you can help yourself in the future.

Arne

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web