JAVA GRAPHICAL USER INTERFACE (GUI) CREATION: Create a Graphical User Interface
ID: 3817408 • Letter: J
Question
JAVA GRAPHICAL USER INTERFACE (GUI) CREATION:
Create a Graphical User Interface (GUI) in Java (Netbeans) that looks like the one below with NO JCOMPONENTS OR JFRAME. USE STANDARD ONLY.
Standard examples:
Button
TextField
RadioButton
GridPane
StackPane
etc etc etc
------------------------------
NO JBUTTON, JTEXTFIELD, JFRAME, JPANEL, ETC ETC ETC
--------------------------------
Sorting Algorithm Selection Bubble Insertion Quick Input Type Already sorted Reverse order Random Input Size 100 Block Size 10 GOExplanation / Answer
Please run the below program:
import java.awt.*;
import java.awt.event.*;
public class AwtControlDemo {
private Frame mainFrame;
private Label headerLabel;
private Label statusLabel;
private Panel controlPanel;
private Panel controlPanel1;
private Panel controlPanel2;
private Panel controlPanel3;
CheckboxGroup sortingGrp = null;
CheckboxGroup InputGrp = null;
public AwtControlDemo(){
prepareGUI();
}
public static void main(String[] args){
AwtControlDemo awtControlDemo = new AwtControlDemo();
awtControlDemo.showButtonDemo();
}
private void prepareGUI(){
mainFrame = new Frame("Examples");
mainFrame.setSize(200,400);
mainFrame.setLayout(new GridLayout(3,1));
mainFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
System.exit(0);
}
});
headerLabel = new Label();
headerLabel.setAlignment(Label.CENTER);
statusLabel = new Label();
statusLabel.setAlignment(Label.CENTER);
statusLabel.setSize(150,100);
controlPanel = new Panel();
controlPanel.setLayout(new FlowLayout());
mainFrame.add(headerLabel);
mainFrame.add(controlPanel);
mainFrame.add(statusLabel);
mainFrame.setVisible(true);
}
private void showButtonDemo(){
headerLabel.setText("Sorting Algorithm");
//create group
sortingGrp = new CheckboxGroup();
InputGrp = new CheckboxGroup();
//create checkboxes and add to group
Checkbox selection = new Checkbox("Selection", sortingGrp, true);
Checkbox bubble = new Checkbox("Bubble", sortingGrp, false);
Checkbox insertion = new Checkbox("Insertion", sortingGrp, false);
Checkbox quick = new Checkbox("Quick", sortingGrp, false);
headerLabel.setText("Sorting Algorithm");
//create checkboxes and add to group
Checkbox alreadysorted = new Checkbox("Already Sorted", InputGrp, true);
Checkbox reverseOrder = new Checkbox("Reverse Order", InputGrp, false);
Checkbox random = new Checkbox("Random", InputGrp, false);
Button goButton = new Button("GO");
Label inputSizeLabel = new Label("Input size");
TextField inputSize = new TextField(20);
Label blockSizeLabel = new Label("Block size");
TextField blockSize = new TextField(20);
goButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
statusLabel.setText("Go Button clicked.");
}
});
controlPanel1 = new Panel();
controlPanel1.setLayout(new FlowLayout());
controlPanel2 = new Panel();
controlPanel2.setLayout(new FlowLayout());
controlPanel3 = new Panel();
controlPanel3.setLayout(new FlowLayout());
controlPanel.add(selection);
controlPanel.add(bubble);
controlPanel.add(insertion);
controlPanel.add(quick);
controlPanel1.add(alreadysorted);
controlPanel1.add(reverseOrder);
controlPanel1.add(random);
controlPanel2.add(inputSizeLabel);
controlPanel2.add(inputSize);
controlPanel2.add(blockSizeLabel);
controlPanel2.add(blockSize);
controlPanel3.add(goButton);
mainFrame.add(controlPanel1);
mainFrame.add(controlPanel2);
mainFrame.add(controlPanel3);
mainFrame.setVisible(true);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.