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
A police officer in a patrol car parked in a 70 km/h speed zone observes a passing automobile traveling at a slow, constant spee
Ludmilka [50]

Answer:

S = 0.5 km

velocity of motorist = 42.857 km/h

Explanation:

given data

speed  = 70 km/h

accelerates uniformly = 90 km/h

time = 8 s

overtakes motorist =  42 s

solution

we know  initial velocity u1 of police = 0

final velocity u2 = 90 km/h = 25 mps

we apply here equation of motion

u2 = u1 + at  

so acceleration a will be

a = \frac{25-0}{8}

a = 3.125  m/s²

so

distance will be

S1 = 0.5 × a × t²

S1 = 100 m = 0.1 km

and

S2 = u2 ×  t

S2 = 25  × 16

S2 = 400 m = 0.4 km  

so total distance travel by police

S = S1 + S2

S = 0.1 + 0.4

S = 0.5 km

and

when motorist travel with  uniform velocity

than total time = 42 s

so velocity of motorist will be

velocity of motorist = \frac{S}{t}

velocity of motorist =  \frac{500}{42}  

velocity of motorist = 42.857 km/h

3 0
3 years ago
Two streams of air enter a control volume: stream 1 enters at a rate of 0.05 kg / s at 300 kPa and 380 K, while stream 2 enters
alex41 [277]

Answer:

0.08kg/s

Explanation:

For this problem you must use 2 equations, the first is the continuity equation that indicates that all the mass flows that enter is equal to those that leave the system, there you have the first equation.

The second equation is obtained using the first law of thermodynamics that indicates that all the energies that enter a system are the same that come out, you must take into account the heat flows, work and mass flows of each state, as well as their enthalpies found with the temperature.

 

finally you use the two previous equations to make a system and find the mass flows

I attached procedure

5 0
3 years ago
Describe three differences between liquids and gases in fluid power systems.<br> Help !!!
scoundrel [369]
Gases, liquids and solids are all made up of atoms, molecules, and/or ions, but the behaviors of these particles differ in the three phases. ... gas are well separated with no regular arrangement. liquid are close together with no regular arrangement. solid are tightly packed, usually in a regular pattern.
3 0
3 years ago
Can glasses be formed using metallic materials?​
Westkost [7]
Metallic glasses are sometimes formed when molten metal is cooled too fast for its atoms to arrange themselves in a structured, crystalline order. "The material can't decide which crystalline structure it wants to converge to, and a metallic glass emerges
5 0
3 years ago
Discuss 7 habits of highly effective people and how important are ethics in today's society​
kompoz [17]

Answer:

Explanation:

The 7 Habits of Highly Effective People, is a book written and first published in 1989. It is a business and self-help book that was written by Stephen Covey. The seven habits include

Being proactive

Starting anything with the end in mind

First things first

Always thinking towards a win-win situation

Seeking initially to understand, then going on to want to be understood

Synergize, and lastly

Growing

7 0
3 years ago
Other questions:
  • What's mutual inductance​
    8·1 answer
  • Estudio de caso Teorema de Bayes. Las historias de casos clínicos indican que diversas enfermedades producen sistemas similares.
    14·1 answer
  • A classroom that normally contains 40 people is to be air-conditioned with window air-conditioning units of 5 kW cooling capacit
    6·1 answer
  • Disc brake rotors that are too thin cannot handle as much heat and will experience ___________.
    6·1 answer
  • All of the following are categories for clutch covers except
    11·1 answer
  • How is air pressure affected by the shape of an aircraft wing
    14·1 answer
  • URGENT PLEASE HELP!!!
    11·1 answer
  • Tech A says that coolant circulates through some intake manifolds to help warm them up. Tech B says that some intake manifolds u
    13·1 answer
  • A continuously variable transmission:
    13·1 answer
  • Why do engineers play a variety of roles in the engineering process?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!