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

JAVA GRAPHICAL USER INTERFACE (GUI) CREATION: Create a Graphical User Interface

ID: 3816757 • 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 GO

Explanation / Answer

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

public class GuiTest {
private JFrame mainFrame;
private JLabel headerLabel;
private JLabel statusLabel;
private JPanel controlPanel;

public GuiTest(){
prepareGUI();
}
public static void main(String[] args){
GuiTest GuiTest = new GuiTest();
GuiTest.showRadioButtonDemo();
}
private void prepareGUI(){
mainFrame = new JFrame("Java Swing Examples");
mainFrame.setSize(400,400);
mainFrame.setLayout(new GridLayout(3, 1));
  
mainFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
System.exit(0);
}
});
headerLabel = new JLabel("", JLabel.CENTER);
statusLabel = new JLabel("",JLabel.CENTER);
statusLabel.setSize(350,100);

controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());

mainFrame.add(headerLabel);
mainFrame.add(controlPanel);
mainFrame.add(statusLabel);
mainFrame.setVisible(true);
}
private void showRadioButtonDemo(){
headerLabel.setText("Sorting algorithm");

final JRadioButton selection = new JRadioButton("selection", true);
final JRadioButton Quick = new JRadioButton("Quick");
final JRadioButton merge = new JRadioButton("Merge");

radselection.setMnemonic(KeyEvent.VK_C);
Quick.setMnemonic(KeyEvent.VK_M);
merge.setMnemonic(KeyEvent.VK_P);

radselection.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {   
statusLabel.setText("Selection RadioButton: "
+ (e.getStateChange()==1?"checked":"unchecked"));
}   
});
Quick.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {   
statusLabel.setText("Quick RadioButton: "
+ (e.getStateChange()==1?"checked":"unchecked"));
}   
});
merge.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {   
statusLabel.setText("Merge RadioButton: "
+ (e.getStateChange()==1?"checked":"unchecked"));
}   
});
  
//Group the radio buttons.
ButtonGroup group = new ButtonGroup();
  
group.add();
group.add(Quick);
group.add(merge);

controlPanel.add(radselection);
controlPanel.add(Quick);
controlPanel.add(merge);   

mainFrame.setVisible(true);
}
}