wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes How to build a frame ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to build a frame ?" Watch "How to build a frame ?" New topic
Author

How to build a frame ?

Vitor Mateucci
Greenhorn

Joined: Oct 06, 2011
Posts: 13
Hi so i wrote this program
So i am wondering how would i go about building a small frame around this to make it look more like an applet?(i think this is the right term??) i just want a small little program where i can have a little boxes where i plug in the variables b,c,d.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10522
    
    9

Recommended reading http://download.oracle.com/javase/tutorial/uiswing/components/applet.html


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2215
    
    7
Applets can't read from the keyboard.

You want to create an application so you should start with How to Make Frames.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
Moving to our GUIs forum.
Vitor Mateucci
Greenhorn

Joined: Oct 06, 2011
Posts: 13
Rob Camick wrote:Applets can't read from the keyboard.

You want to create an application so you should start with How to Make Frames.


Hi,

Thanks for the link i was able to make a blank frame but i still dont understand,

how would i go about adding my program to the frame?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
java Foo "Campbell\'s GUI"

There is an error hidden somewhere in that code. It isn’t intentional, but rather than correcting it, I’ll let you find it for yourself. Don’t anybody else tell him
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2215
    
    7
You wouldn't add your program to the frame. Working with a GUI is different than working with the keyboard.

For example you might use a JOptionPane to prompt the user for data. Then once the user enters all the data you might use a JLabel to display the data.

Or you can create a simple JDialog that contains 3 JTextFields where the user can enter all 3 pieces of information at one time.

Read the tutorial and start playing with the different Swing components. Every section in the tutorial comes with working examples that you can download and test.
Vitor Mateucci
Greenhorn

Joined: Oct 06, 2011
Posts: 13
Campbell Ritchie wrote:java Foo "Campbell\'s GUI"

There is an error hidden somewhere in that code. It isn’t intentional, but rather than correcting it, I’ll let you find it for yourself. Don’t anybody else tell him


Isn't the error on line 17 where you put a ) instead of a }
Vitor Mateucci
Greenhorn

Joined: Oct 06, 2011
Posts: 13
Rob Camick wrote:You wouldn't add your program to the frame. Working with a GUI is different than working with the keyboard.

For example you might use a JOptionPane to prompt the user for data. Then once the user enters all the data you might use a JLabel to display the data.

Or you can create a simple JDialog that contains 3 JTextFields where the user can enter all 3 pieces of information at one time.

Read the tutorial and start playing with the different Swing components. Every section in the tutorial comes with working examples that you can download and test.


Ohhh ok i am starting to understand it now but then where would i put the arithmetic?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
Vitor Mateucci wrote: . . . Isn't the error on line 17 where you put a ) instead of a }
No. That ) matches the ( after invokeLater. The error is something different. And the ... ellipses don’t count.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2215
    
    7
You put the arithmetic in the same place you put it before.

Before you prompted the user for input and got the value the user typed. Once you have all the values you did the arithmetic.

This is the same. The difference is that you are promting the user for input from a GUI, instead of the console.
Vitor Mateucci
Greenhorn

Joined: Oct 06, 2011
Posts: 13
Rob Camick wrote:You put the arithmetic in the same place you put it before.

Before you prompted the user for input and got the value the user typed. Once you have all the values you did the arithmetic.

This is the same. The difference is that you are promting the user for input from a GUI, instead of the console.


Ohh i understand now thank you,

I'll try posting up the final code once i finish
Vitor Mateucci
Greenhorn

Joined: Oct 06, 2011
Posts: 13
Campbell Ritchie wrote:
Vitor Mateucci wrote: . . . Isn't the error on line 17 where you put a ) instead of a }
No. That ) matches the ( after invokeLater. The error is something different. And the ... ellipses don’t count.


Is it the extra = ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
No.

But at least you have found the line with the error.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
There is a second error, but it will become obvious if you try to run my code; the compiler error will tell you everything.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
Shall I let you out of your misery?

  • When I tried to compile it, I had to change the args array to final. That is standard when a local variable or parameter is used by an anonymous class.
  • If you have args.length == 0, all is well. But if you pass a 1-element args array, you will get an Exception for args[1]. That should of course read args[0].
  •  
    Consider Paul's rocket mass heater.
     
    subject: How to build a frame ?