Answer to Question #237331 in Java | JSP | JSF for Felly

Question #237331

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




1
Expert's answer
2021-09-15T02:29:18-0400
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


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS