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
Define and discuss the difference between micronutrients and macronutrients. Also, discuss their importance in the body at rest
almond37 [142]

Answer:

Macronutrients are simply nutrients the body needs in a very high amount e.g Carbohydrate.

MicroNutrients are simply nutrients the body needs but in little amount e.g  Minerals.

Explanation:

So for further breakdown:

What are nutrients? Nutrients are essential elements that nourish the body in different capacities. We as humans get most of out nutrients from the food and water we ingest.

Now about Macro Nutrients: From the prefix "Macro" which means large, we can infer that macro nutrients are elements need by the body for the fundamental processes of the body, deficiency in this nutrients are very easy to spot. Examples are: Carbohydrates, Protein, Fats amd Water.

Micro Nutrients: In relation to macro nutrients this are elements that the body needs but are not needed in Large quantities. They mostly work like supporting nutrients. Most chemical activities like reaction that occur in the body are a function of micro nutrients. Defiencies in micrp nutrients may take some time to spot e.g Minerals and Vitamins

In regards to exercise: Macro nutrients are the essential ones here since they are the ones that generate energy. PS: micro nutrients dont generate energy.

In regards to rest: Both the Macro and Micro Nutrients are essentail for the overall well being of the body.

5 0
3 years ago
In the lab, a container of saturated soil had a mass of 113.27 g before it was placed in the oven and100.06 g after the soil had
kipiarov [429]

Answer:

  • Moisture/ water content w = 26%
  • Void ratio , e =  0.73

Explanation:

  • Initial mass of saturated soil w1 = mass of soil - weight of container

                                                 = 113.27 g - 49.31 g = 63.96 g

  • Final mass of soil after oven w2 = mass of soil - weight of container

                                                  = 100.06 g - 49.31 g = 50.75

Moisture /water content, w =   \frac{w1-w2}{w2} = \frac{63.96-50.75}{50.75} = 0.26 = 26%

Void ratio =  water content X specific gravity of solid

                  = 0.26 X 2.80 =0.728

5 0
3 years ago
Which career best fits the group of the words below? High voltage, lines
Llana [10]

Answer:

I forget the word for it, but probably the guys who set up the power lines in the city.

Explanation:

5 0
3 years ago
Read 2 more answers
Engineering controls are the physical changes that employers make to the work environment or to equipment that make it safer to
____ [38]

Answer:

Engineering Controls. The best engineering controls to prevent heat-related illness is to make the work environment cooler and to reduce manual workload with mechanization. A variety of engineering controls can reduce workers' exposure to heat: Air conditioning, Increased general ventilation , Cooling fans , Local exhaust ventilation at points of high heat production or moisture, Reflective shields to redirect radiant heat , Insulation of hot surfaces Elimination of steam leaks , Cooled seats or benches for rest breaks , Use of mechanical equipment to reduce manual work, Misting fans that produce a spray of fine water droplets.

Hope this helped you!

Explanation:

5 0
4 years ago
What are the indicators of ineffective systems engineering?
liberstina [14]

Answer:

Indicators for ineffective system engineering are as follows

1.Requirement trends

2.System definition change backlog trends

3.interface trends

4.Requirement validation trends

5.Requirement verification trends

6.Work product approval trends

7.Review action closure trends

8.Risk exposure trends

9.Risk handling trends

10.Technology maturity trends

11.Technical measurement trends

12.System engineering skills trends

13.Process compliance trends

7 0
3 years ago
Other questions:
  • 12. Dies are turned using a special tool called a/an
    10·1 answer
  • 3- A cylinder with 0.4kg of Nitrogen gas at 27ºC keeps under pressure by a frictionless piston. Weight of this piston will incre
    6·1 answer
  • A gas contained within a piston-cylinder undergoes the follow change in states: Process 1: Constant volume from p1 = 1 bar V1 =
    9·1 answer
  • Air enters a tank through an area of 0.2 ft2 with a velocity of 15 ft/s and a density of 0.03 slug/ft3. Air leaves with a veloci
    5·1 answer
  • Impact strips may be designed into a bumper cover.<br> True<br> False
    14·1 answer
  • Which of the following refers to a full-scale version of a product used to validate performance?
    10·2 answers
  • A 100-mm-diameter cast Iron shaft is acted upon by a 10 kN.m bending moment, a 8 kN.m torque, and a 150 kN axial force simultane
    9·1 answer
  • Which of the following activities could be considered unethical?
    7·1 answer
  • How to create ground responce analysis using matlab
    6·1 answer
  • Thermal energy measured by?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!