Solve this question Write a Java application to display the following GUI. At th
ID: 3534484 • Letter: S
Question
Solve this question
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();
}
}