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

How to set up a simple GUI based on JFrame Setting up listeners and responding t

ID: 3828058 • Letter: H

Question

How to set up a simple GUI based on JFrame Setting up listeners and responding to events Drawing simple shapes Dealing with mouse and mouse motion events Directions l. Write a GUI application in Java using Swing that has three buttons and a drawing area 2. Give the window an initial size of 800 x 800 pixels, and put your name in the menu bar. 3. The buttons should be at the top of the window and be labeled "Ova Rectangle", and Specia 4. The drawing area should cover the remainder of the window. 5. When it starts, the program should show nothing in the drawing area, but the background of the drawing area should be a non-white color. 6. Pressing the Oval or Rectangle buttons should toggle (turn on or off the display of an oval or rectangle, either or both of which must be visible at the same time. When drawn, the oval and rectangle should be different colors of your choice 7. You must also be able to click and drag the rectangle or oval around the screen with the mouse 8. When the user presses the "special" button, the program should do something else not described in the assignment that is unique to your program, such as change the color of all the things you draw, switch the oval to be outlines instead of filled, or draw your name in the middle of the window. 9. As always, make sure the proper block comment is at the top of your main file with your name 10. Once your program is working, pass it off directly to the instructor or TA. Also, turn in your code to D2L.

Explanation / Answer

import java.awt.event.*;
import java.awt.EventQueue;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import javax.swing.border.Border;
import javax.swing.text.DefaultCaret.*;

public class gui extends JFrame
     implements Listener {

     private boolean showText = false;
     private boolean showRect = true;
     private boolean showOval = false;
    
     private JButton oval;
     private JButton rectangle;
     private JButton special;
private JPanel buttonPanel;
    
private DrawStuff drawPanel = new DrawStuff();

     public firstGUI() {
         super("First GUI");
         setSize(800, 800);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

         buttonPanel = new JPanel();
         buttonPanel.setLayout(new GridLayout(1, 3));

         oval = new JButton("Oval");
         oval.addActionListener(this);
         buttonPanel.add(oval);

         rectangle = new JButton("Rectangle");
         rectangle.addActionListener(this);
         buttonPanel.add(rectangle);

   special = new JButton("special");
         special.addActionListener(this);
         buttonPanel.add(special);

         Container contentPane = this.getContentPane();
         contentPane.add(buttonPanel, BorderLayout.NORTH);
         add(drawPanel);
    }
public static void main(String[] args) {
  EventQueue.invokeLater(new Runnable() {
   public void run() {
    try {
     gui window = new gui();
     window.frame.setVisible(true);
    } catch (Exception e) {
     e.printStackTrace();
    }
   }
  });
}
public gui() {
  initialize();
}
private void initialize() {
  frame = new JFrame();
  frame.getContentPane().setFont(new Font("Arial", Font.PLAIN, 11));
  frame.getContentPane().setForeground(new Color(0, 0, 0));
  frame.setBounds(100, 100, 1000, 700);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.getContentPane().setLayout(null);
  
  
  
  JLabel lblNamedEntityRecognition = new JLabel("sravani");
  lblNamedEntityRecognition.setBounds(193, 11, 487, 28);
  lblNamedEntityRecognition.setForeground(Color.MAGENTA);
  lblNamedEntityRecognition.setFont(new Font("Times New Roman", Font.BOLD | Font.ITALIC, 24));
  frame.getContentPane().add(lblNamedEntityRecognition);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote