Java Code Help!
Author |
Message |
Lucman909
|
Posted: Mon Jul 05, 2010 5:18 pm Post subject: Java Code Help! |
|
|
Hey, kso ive read a lot and for a long time in Java, and i thought i would try to make a simple window. Here is my code.
import java.awt.*;
import javax.swing.*;
import JFrame;
public class Window{
private static void creatWindow(){
// The Top Of The Window
JFrame frame = new JFrame("simpleWindow");
frame.setDefaultCloseoperation(Frame.EXIT_ON_CLOSE);
//The Dimentions And What The Box Will Do
JLable textLable = new Jlable("Put Anything You Wish Here", SwingConstants.CENTER);
textLable.setPreferredsize(new Dimension(200,100));
frame.getContentPane().add(textLabel, BorderLayout.CENTER);
// Displays The Window
frame.pack();
frame.setvisible(true);
}
public static void main(String[] args) {
creatWindow();
}
}
It looks okay to me, but when i try to compile it doesn't ! If you know any Java and think you can help. PLEASE DO SO!
Thanks ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
TheGuardian001
|
Posted: Mon Jul 05, 2010 5:42 pm Post subject: Re: Java Code Help! |
|
|
Well, let's see...
You didn't define the package to get JFrame from (should be javax.swing.JFrame, which is already covered by import javax.swing.*)
code: |
frame.setDefaultCloseoperation(Frame.EXIT_ON_CLOSE);
|
Your window is a JFrame, and you should be using JFrame constants. On top of which, java is Case Sensitive. The "o" at the start of "operation" should be capitalised.
code: |
JLable textLable = new Jlable("Put Anything You Wish Here", SwingConstants.CENTER);
|
JLabel(el, not le) is spelt incorrectly, and once again, Java is case sensitive. Your second Jlabel should have a capital L. (You also spelt "textLabel" many different ways, check your spelling on each one).
code: |
textLabel.setPreferredsize(new Dimension(200,100));
...
frame.setvisible(true);
|
cASe SeNsiTIvE (setPreferredSize, setVisible) |
|
|
|
|
![](images/spacer.gif) |
Lucman909
|
Posted: Mon Jul 05, 2010 6:11 pm Post subject: RE:Java Code Help! |
|
|
Thanks So Much!
that really helped! ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
|
|