Solved: Write a Java application to display the following …

$30.00

Category:

Description

Solved: Write a Java application to display the following …

Write a Java application to display the following GUI. At this point you are only implementing the display.

 

This program has the following requirements:

 

1.The textfield should accommodate 3 characters.

2.The X and Y labels should be next to the corresponding textfields.

Hint: Put each label and its adjacent text field into a panel, then put both panels into another panel!

3.The buttons should have 10 pixels horizontal spacing and 5 pixels vertical spacing.

4.For the layout of the JFrame, use FlowLayout( FlowLayout.CENTER, 10, 5).

5.Your application should be implemented in a single class. The main method of the class does nothing more than create an object of the class. The constructor of the class creates and displays the GUI. The constructor may call other methods of the class if needed.

6.Do not use inheritance for this program. Use a JFrame member variable as the main window object for this program.

 

This is what I have so far:

I don’t know what I am doing wrong? Also, it needs to look like the image above.

 

import javax.swing.*;

import java.awt.*;

public class AlignGUI {

JPanel y, x, left, center, right;

JLabel labelY, labelX;

JCheckBox check1, check2;

JButton ok, cancel, help;

JTextField textX, textY;

JFrame frame;

JPanel fieldJPanel ,fieldJPanel1, fieldJPanel2;

 

 

 

AlignGUI(){

check1 = new JCheckBox(“Snap to Grid”, false);

check2 = new JCheckBox(“Show Grid”, false);

labelX = new JLabel(“X: “);

textX = new JTextField(“12”, 3); //set width of the text field

fieldJPanel2 = new JPanel();

fieldJPanel2.setLayout(new FlowLayout());

fieldJPanel2.add(labelX);

fieldJPanel2.add(textX);

//Build field Panel

fieldJPanel = new JPanel();

fieldJPanel.setLayout(new BorderLayout());

fieldJPanel.add(fieldJPanel1, BorderLayout.NORTH);

fieldJPanel.add(fieldJPanel2, BorderLayout.SOUTH);

labelY = new JLabel(“Y: “);

textY = new JTextField(“12”, 3); //set width of the text field

fieldJPanel2 = new JPanel();

fieldJPanel2.setLayout(new FlowLayout());

fieldJPanel2.add(labelY);

fieldJPanel2.add(textY);

//Build field Panel

fieldJPanel = new JPanel();

fieldJPanel.setLayout(new BorderLayout());

fieldJPanel.add(fieldJPanel1, BorderLayout.NORTH);

fieldJPanel.add(fieldJPanel2, BorderLayout.SOUTH);

ok = new JButton(“OK”);

cancel = new JButton(“Cancel”);

help = new JButton(“Help”);

frame.add(check1, BorderLayout.WEST);

frame.add(check2, BorderLayout.WEST);

frame.add(fieldJPanel);

frame.add(ok, BorderLayout.EAST);

frame.add(cancel, BorderLayout.EAST);

frame.add(help, BorderLayout.EAST);

frame.setSize(300, 300);

frame.setLayout(new FlowLayout( FlowLayout.CENTER, 10, 5));

frame.setLocationRelativeTo(null);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

 

}

 

public static void main(String[] args)

{

AlignGUI align = new AlignGUI();

}

 

}

 


error: Content is protected !!