1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Delicious77 [7]
3 years ago
8

This assignment is designed to test your understanding of graphical user interface components and Event Driven programming in Ja

va using Swing. You will write and attach event handlers to an existing graphical user interface (GUI) for an application that displays and manipulates a Color Model.
Engineering
1 answer:
lys-0071 [83]3 years ago
7 0

Answer:

Java program is given below

Explanation:

JavaPadGUI.java

package javapad.gui;

import java.awt.BorderLayout;

import java.awt.Container;

import java.awt.Dimension;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.PrintWriter;

import java.util.Scanner;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTextArea;

public class JavaPadGUI extends JFrame implements ActionListener{

  //constants

  private static final String TITLE = "Macrosoft JavaPad XP";

  private static final String SLOGAN = "Macrosoft: Resistance is futile";

 

  //button names

  private static final String NEW = "New";

  private static final String LOAD = "Load";

  private static final String SAVE = "Save";

  private static final String QUIT = "Quit";

 

  private static final String FILENAME = "hardcode.txt";

  //messages

 

  private static final String QUIT_MSG = "Quitting, Save?";

  private static final String LOAD_ERR = "Could not access file " + FILENAME;

 

 

  //fields

  private JTextArea txtContent;

  private JButton butNew, butLoad, butSave, butQuit;

 

  public JavaPadGUI()

  {

      super(TITLE);

      createUI();

      setSize(new Dimension(400, 300));

      setDefaultCloseOperation(EXIT_ON_CLOSE);

         

  }

 

  private void createUI()

  {

      Container c = getContentPane();

      c.setLayout(new BorderLayout(30,30));

     

      //create the buttons panel

      JPanel butPanel = new JPanel();

      butPanel.add(butNew = new JButton(NEW));

      butPanel.add(butLoad = new JButton(LOAD));

      butPanel.add(butSave = new JButton(SAVE));

      butPanel.add(butQuit = new JButton(QUIT));

     

      //set command names for the buttons, these will be when button is clicked

      butNew.setActionCommand(NEW);

      butLoad.setActionCommand(LOAD);

      butSave.setActionCommand(SAVE);

      butQuit.setActionCommand(QUIT);

     

      JPanel sloganPanel = new JPanel();

      sloganPanel.add(new JLabel(SLOGAN));

     

      //create textarea with scrollbar

      txtContent = new JTextArea(15, 25);

      txtContent.setLineWrap(true);

         

      JScrollPane scroll = new JScrollPane(txtContent);

     

      //now add all components

      c.add(butPanel, BorderLayout.NORTH);

      c.add(scroll, BorderLayout.CENTER);

      c.add(sloganPanel, BorderLayout.SOUTH);

     

     

      //set the actionlistner to buttons to handle button click event

      butNew.addActionListener(this);

      butLoad.addActionListener(this);

      butSave.addActionListener(this);

      butQuit.addActionListener(this);

     

  }

  public void actionPerformed(ActionEvent e)

  {

      String cmd = e.getActionCommand();

      if(cmd.equals(NEW))

          txtContent.setText("");

      else if (cmd.equals(LOAD))

          load();

      else if(cmd.equals(SAVE))

          save();

      else if (cmd.equals(QUIT))

          quit();

  }

  private void quit()

  {

      int option = JOptionPane.showConfirmDialog(this, QUIT_MSG);

      if(option == JOptionPane.YES_OPTION)

      {

          save();

      }

     

      System.exit(0);

  }

 

  private void save()

  {

      try {

          PrintWriter w = new PrintWriter(new File(FILENAME));

          w.write(txtContent.getText());

          w.close();

      } catch (FileNotFoundException e) {

          JOptionPane.showMessageDialog(this,"I/O Error", LOAD_ERR, JOptionPane.ERROR_MESSAGE);

      }

             

  }

  private void load()

  {

      try {

          Scanner s = new Scanner(new File(FILENAME));

          String str = "";

          while(s.hasNextLine())

              str += s.nextLine();

          txtContent.setText(str);

          s.close();

      } catch (FileNotFoundException e) {

          JOptionPane.showMessageDialog(this, LOAD_ERR, "I/O Error",JOptionPane.ERROR_MESSAGE);

      }

     

  }

}

RunJavaPad.java

package javapad;

import javapad.gui.JavaPadGUI;

public class RunJavaPad {

  public static void main(String[] args) {

      JavaPadGUI gui = new JavaPadGUI();

      gui.setVisible(true);

  }

}

You might be interested in
Cynthia is producing a sculpture using material introduced in the Bronze Age. What two metals is she mixing?
Airida [17]
The correct answer
would be d
Iron and carbon
hope this helps
5 0
3 years ago
Technician A says that ultraviolet light is bright, and very hot. Technician B says that ear protection does not need to be used
-Dominant- [34]

Answer:

a. technician a only

Explanation:

I took that worksheet

3 0
3 years ago
Refrigerant-134a enters a 28-cm-diameter pipe steadily at 200 kPa and 20°C with a velocity of 5 m/s. The refrigerant gains heat
Alexandra [31]

Answer:

V = 0.30787 m³/s

m = 2.6963 kg/s

v2 =  0.3705 m³/s

v2 = 6.017 m/s

Explanation:

given data

diameter = 28 cm

steadily =200 kPa

temperature = 20°C

velocity = 5 m/s

solution

we know mass flow rate is

m = ρ A v

floe rate V = Av

m = ρ V

flow rate = V = \frac{m}{\rho}

V = Av = \frac{\pi}{4} * d^2 * v1

V = \frac{\pi}{4} * 0.28^2 * 5

V = 0.30787 m³/s

and

mass flow rate of the refrigerant is

m = ρ A v

m = ρ V

m = \frac{V}{v} = \frac{0.30787}{0.11418}

m = 2.6963 kg/s

and

velocity and volume flow rate at exit

velocity = mass × v

v2 = 2.6963 × 0.13741 = 0.3705 m³/s

and

v2 = A2×v2

v2 = \frac{v2}{A2}

v2 = \frac{0.3705}{\frac{\pi}{4} * 0.28^2}

v2 = 6.017 m/s

7 0
3 years ago
Use the concept that y = c, −[infinity] < x < [infinity], is a constant function if and only if y' = 0 to determine whethe
attashe74 [19]

Answer:

attached below

Explanation:

5 0
3 years ago
30 points and brainiest if correct please help A, B, C, D
tatuchka [14]

Answer:

B. to lock the tape into place

Explanation:

the button on the front of the housing locks the tape into place when pressed, preventing the tape from being pulled out further it retracting

4 0
3 years ago
Other questions:
  • The wet density of a sand was found to be 1.9 Mg/m3 and the field water content was 10%. In the laboratory, the density of solid
    9·1 answer
  • In order to test the feasibility of drying a certain foodstuff, drying data were obtained in a tray dryer with air flow over the
    14·1 answer
  • Create a program named IntegerFacts whose Main() method declares an array of 10 integers.Call a method named FillArray to intera
    12·1 answer
  • #198. Moment of inertia about center of a segmented bar A bar of width is formed of three uniform segments with lengths and area
    7·1 answer
  • The following is a list of metals and alloys:
    10·1 answer
  • Q1. Basic calculation of the First law (2’) (a) Suppose that 150 kJ of work are used to compress a spring, and that 25 kJ of hea
    6·1 answer
  • Would be much appreciated if someone could help with this will give brainiest.
    6·1 answer
  • Why might many general contractors begin their careers as construction workers?
    9·1 answer
  • Why does the compression-refrigeration cycle have a high-pressure side and a low-pressure side?
    7·1 answer
  • Technician a says that personal protective equipment (ppe) does not include clothing. technician b says that the ppe used should
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!