Question

Using IntelliJ create a Java GUI window program that contains all the interface components covered in...

Using IntelliJ create a Java GUI window program that contains all the interface components covered in the lecture.

JPanel - Green with Yellow text

JButton - four buttons

JLabel - four labels

JTextField - three text fields

JPasswordField - one is fine

JCheckBox - four different birds

JComboBox - four different flowers

JList - three different bikes

JSlider - goes up to max 100 at 10 increments

JMenu - contains File with pull down options-> save -> save all

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

code:


/**
* The java class GUIInterface that contains
* gui interface elements to the jpanel.
* */
//GUIInterface.java
import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JSlider;
public class GUIInterface
{  
   public static void main(String[] args)
   {      
       final int APP_WIDTH=350;
       final int APP_HEIGHT=350;
       //Create a frame instance
       JFrame frame=new JFrame();
       //set title
       frame.setTitle("GUIInterface");
       //set size
       frame.setSize(APP_WIDTH, APP_HEIGHT);
       //calling createGui method
       frame.add(createGUI());
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       //set visible true
       frame.setVisible(true);
      
   }

   /**
   * The static method that is used to create
   * all the interface elements and returns
   * the component of type jpanel
   * */
   private static Component createGUI() {
       JPanel guiPanel=new JPanel();
       guiPanel.setLayout(new FlowLayout());
       guiPanel.setBackground(Color.green);
      
       //Adding 4 buttons
       for (int i = 0; i < 4; i++)
           guiPanel.add(new JButton("Button : "+(i+1)));
      
       //Adding 4 labels
       for (int i = 0; i < 4; i++)
           guiPanel.add(new JLabel("Label : "+(i+1)));
       //Adding password field
       guiPanel.add(new JPasswordField(15));
      
       //Adding check boxes
       guiPanel.add(new JCheckBox("crane"));
       guiPanel.add(new JCheckBox("Pigeon"));
       guiPanel.add(new JCheckBox("Crow"));
       guiPanel.add(new JCheckBox("Dove"));
      
       String flowers[]={"Rose","Jasmine","Lilly","Lotus"};
       JComboBox<String >flowerBox=
               new JComboBox<String>(flowers);
       //Adding combo box
       guiPanel.add(flowerBox);
      
       String bikes[]={"Honda 120","Pulsar 220","Hunk"};
       JList<String>bikesList=new JList<>(bikes);
       //Adding list box
       guiPanel.add(bikesList);
      
       //adding slider
       JSlider slider=new JSlider(0, 100, 10);
       guiPanel.add(slider);
      
       //Creating menu bar
       JMenuBar menubar=new JMenuBar();
       JMenu menu=new JMenu("File");
       menu.add(new JMenuItem("Save"));
       menu.add(new JMenuItem("Save All"));
       menubar.add(menu);
      
       guiPanel.add(menubar);
      
       //return guipanel
       return guiPanel;
   }
}//end of class

Output:

Please, please upvote and ask your doubts in the comments.

Add a comment
Know the answer?
Add Answer to:
Using IntelliJ create a Java GUI window program that contains all the interface components covered in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • GUI in java: Run the below code before doing the actionlistener: import java.awt.*; import javax.swing.*; public...

    GUI in java: Run the below code before doing the actionlistener: import java.awt.*; import javax.swing.*; public class DrawingFrame extends JFrame {    JButton loadButton, saveButton, drawButton;    JComboBox colorList, shapesList;    JTextField parametersTextField;       DrawingFrame() {        super("Drawing Application");        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        JToolBar toolbar = new JToolBar();        toolbar.setRollover(true);        toolbar.add(loadButton=new JButton("Load"));        toolbar.add(saveButton=new JButton("Save"));        toolbar.addSeparator();        toolbar.add(drawButton=new JButton("Draw"));               toolbar.addSeparator();        toolbar.addSeparator();        toolbar.add(new...

  • Lab Assignment : In this lab, you are going to implement QueueADT interface that defines a...

    Lab Assignment : In this lab, you are going to implement QueueADT interface that defines a queue. Then you are going to use the queue to store animals. 1. Write a LinkedQueue class that implements the QueueADT.java interface using links. 2. Textbook implementation uses a count variable to keep track of the elements in the queue. Don't use variable count in your implementation (points will be deducted if you use instance variable count). You may use a local integer variable...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT