Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Solve this question Write a Java application to display the following GUI. At th

ID: 3534484 • Letter: S

Question

Solve this question


Write a Java application to display the following GUI. At this point you are only implementing the display. This program has the following requirements: The textfield should accommodate 3 characters. The V1 and V2 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! The buttons should have 10 pixels horizontal spacing and 5 pixels vertical spacing. For the layout of the JFrame, use FlowLayout( FlowLayout. CENTER. 10, 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. Do not use inheritance for this program. Use a JFrame member variable as the main window object for this program. Take screen shots of the output of programs 1 & 2. Paste the screen shots and your

Explanation / Answer

this is the working code to display the above GUI

---------------------------------------------------------------------


import javax.swing.*;

import java.awt.*;

public class Align extends JFrame {

JButton cancel = new JButton("Cancel");

JButton help = new JButton("Help");

JButton ok = new JButton("OK");

JCheckBox crispy=new JCheckBox("Extra Crispy");

JCheckBox mushy=new JCheckBox("Mushy");

JTextField txt1 = new JTextField("123");

JTextField txt2 = new JTextField("456");

JLabel v1=new JLabel("V1 :");

JLabel v2=new JLabel("V2 :");


JPanel panelV1=new JPanel();

JPanel panelV2=new JPanel();


JPanel textPanel=new JPanel();

JPanel buttonPanel=new JPanel();

JPanel checkPanel=new JPanel();

public Align() {

Container c = getContentPane();

c.setLayout(new FlowLayout(FlowLayout.LEFT,10,5));

  

// this is for button panel

buttonPanel.setLayout(new GridLayout(3,0,5,5));

buttonPanel.add(cancel);

buttonPanel.add(help);

buttonPanel.add(ok);

c.add(buttonPanel);

  

// this is for checkbox panel

checkPanel.setLayout(new GridLayout(2,0,5,5));

checkPanel.add(crispy);

checkPanel.add(mushy);

c.add(checkPanel);

  

// this is for text box and label

panelV1.add(v1);

panelV1.add(txt1);

panelV2.add(v2);

panelV2.add(txt2);

textPanel.setLayout(new GridLayout(2,0,5,5));

textPanel.add(panelV1);

textPanel.add(panelV2);

c.add(textPanel);

  

Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

  

setSize(300,140);

int w = getSize().width;

int h = getSize().height;

int x = (dim.width-w)/2;

int y = (dim.height-h)/2;

setLocation(x, y);

setVisible(true);

setDefaultCloseOperation(EXIT_ON_CLOSE);

}


public static void main(String[] args) {

Align a = new Align();

}

}