PDA

View Full Version : Java GUI question


davidc2
10-02-2006, 09:14 AM
I need to make this:
http://www.wtfhost.com//files/34/this2.jpg

look like this:
http://www.wtfhost.com//files/34/this.jpg

But I don't know how to...
Here's the code, can you give me a hand?



import java.awt.GridLayout;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JButton;

public class Align extends JFrame
{
private JTextField textField; // text field
private JTextField textField2;

private JCheckBox snapToGrid;
private JCheckBox showGrid;
private JLabel label1;
private JLabel label2;

private JButton button1;
private JButton button2;
private JButton button3;

private GridLayout gridLayout1;
private Container container;

private GridLayout gridLayout2;
private Container container2;

// CheckBoxFrame constructor adds JCheckBoxes to JFrame
public Align()
{
super( "Align" );
gridLayout1 = new GridLayout( 3, 3, 5, 5 );
container = getContentPane();

setLayout( gridLayout1 ); // set frame layout

snapToGrid = new JCheckBox( "Snap to Grid" );
showGrid = new JCheckBox( "Show Grid" );
add( snapToGrid );

label1 = new JLabel( "X:" );
add ( label1 );

// set up JTextField and set its font
textField = new JTextField( " ", 3 );
textField.setFont( new Font( "Serif", Font.PLAIN, 14 ) );
add( textField ); // add textField to JFrame


add( showGrid );

label2 = new JLabel( "Y:" );
add ( label2 );

// set up JTextField and set its font
textField2 = new JTextField( " ", 3 );
textField2.setFont( new Font( "Serif", Font.PLAIN, 14 ) );
add( textField2 ); // add textField to JFrame


button1 = new JButton( "OK" );
add (button1);

button2 = new JButton( "Cancel" );
add (button2);

button3 = new JButton( "Help" );
add (button3);


} // end constructor


} // end class

and



import javax.swing.JFrame;

public class Align_Test
{
public static void main( String args[] )
{
Align align = new Align();
align.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
align.setSize( 275, 140 ); // set frame size
align.setVisible( true ); // display frame
} // end main
} // end class

Aradon
10-02-2006, 09:36 AM
Given the pictures, this smells like homework, so I"ll give some advice on the matter, rather then code.

Obviously java gui's have different kinds of layouts that one can use. The bad news is, these layouts can get tricky at times...

The good news is you can stack as many layouts as you wont on top of each other.

So for example you can have a BorderLayout that controls the east and west with two different grid layouts on top in order to control position. There are plenty of tutorials out there on using multiple layouts with different panes, it's just a short google search away.

Hope that helps.

davidc2
10-02-2006, 10:09 AM
Yes, that stacking is that I don't understand... I thought about using border and inside that I could use flow, but I don't know how to do it =\

Can you give me a hand.

davidc2
10-02-2006, 11:28 AM
Wow I got it, it's really interesting... I'll post the answers later to this and another examples for future research :)

Right now I'm going to finish some other exercises :)

Lallo
10-02-2006, 11:37 AM
Try NetBeans it is amazing!!!!!!!!!!!!!!!

DELOCH
10-02-2006, 07:56 PM
I think you import too much:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

should handle all your work ;)

davidc2
10-03-2006, 02:05 AM
Try NetBeans it is amazing!!!!!!!!!!!!!!!

It is but I actually had to do the code :)

davidc2
10-03-2006, 02:06 AM
I think you import too much:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

should handle all your work ;)

roger :thumbsup:

Aradon
10-03-2006, 09:25 AM
Try NetBeans it is amazing!!!!!!!!!!!!!!!

Eclipse > NetBeans

But this is a debate that really has no end.