Create a window (program) that will run as a standalone application. Your program must contain the following components:
A label
A button
A check box
A text field with a vertical scroll bar
package com.company;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
public class Main {
public static void main(String[] args) {
//creating a frame
JFrame frame = new JFrame();
frame.setTitle("My Java program assignment");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
//creating a panel
JPanel panel1 = new JPanel();
panel1.setBounds(100,50,400,400);
panel1.setLayout(new GridLayout(8,1));
panel1.setBorder(new TitledBorder("My assignment succesfully solved"));
//creating a textfiled
JTextField txt = new JTextField();
//create a scrollpane for the textfield
JScrollPane scrollPane = new JScrollPane(txt);
//set the scroolpane to be vertical
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setPreferredSize(new Dimension(100, 40));
panel1.add(scrollPane);
panel1.add(new JLabel("(Label) Give a brief description of who you are:"));
panel1.add(scrollPane);
// creating check boxes
JCheckBox checkBox1 = new JCheckBox("C++");
checkBox1.setBounds(100,20, 50,50);
JCheckBox checkBox2 = new JCheckBox("Java");
checkBox1.setBounds(100,20, 50,50);
JCheckBox checkBox3 = new JCheckBox("Python");
checkBox1.setBounds(100,20, 50,50);
JCheckBox checkBox4 = new JCheckBox("Kotlin");
checkBox1.setBounds(100,20, 50,50);
panel1.add(new JLabel("(LAbel) Select Programming languages you good at:"));
panel1.add(checkBox1);
panel1.add(checkBox2);
panel1.add(checkBox3);
panel1.add(checkBox4);
panel1.add(new JButton("Submit button"));
frame.add(panel1,BorderLayout.NORTH);
frame.setVisible(true);
frame.pack();
}
}
This is the output of the program
Thank you
Comments
Leave a comment