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
John has an exhaust leak in his Acura Integra GS-R, What steps would he take to fix the leak in time for his inspection?
SCORPION-xisa [38]

Answer:

Explanation:

Fist you need to identify where the leak is coming from. You can do this by either listening for the leak or spraying soapy water on the exhaust to look for air bubbles coming out of the exhaust. Depending on the spot of the leak there are many ways you can fix this leak.

1. Exhaust clamp

2. Exhaust putty

3. Exhaust tape

4. New exhaust

Exhaust clamp is best used for holes on straight pipes.

Putty is best used on welds or small holes like on exhaust manifolds or welds connecting various pieces like catalytic converters, mufflers, or resonators.

Tape will work best on straight pipes with holes.

New exhaust is for when the thig is beyond repair, like rust.

Now good luck because working on exhausts is a pain.

4 0
2 years ago
1) Relative to electrons and electron states, what does each of the four quantum numbers specify?
Naily [24]

Answer:

Cite two important additional refinements that resulted from the Wave-mechanical

atomic model.

4 0
3 years ago
Consider a single crystal of nickel oriented such that a tensile stress is applied along a [001] direction. If slip occurs on a
Elena L [17]

Answer:

\mathbf{\tau_c =5.675 \ MPa}

Explanation:

Given that:

The direction of the applied tensile stress =[001]

direction of the slip plane = [\bar 101]

normal to the slip plane = [111]

Now, the first thing to do is to calculate the angle between the tensile stress and the slip by using the formula:

cos \lambda = \Big [\dfrac{d_1d_2+e_1e_2+f_1f_2}{\sqrt{(d_1^2+e_1^2+f_1^2)+(d_2^2+e_2^2+f_2^2) }} \Big]

where;

[d_1\ e_1 \ f_1] = directional indices for tensile stress

[d_2 \ e_2 \ f_2] = slip direction

replacing their values;

i.e d_1 = 0 ,e_1 = 0 f_1 =  1 & d_2 = -1 , e_2 = 0 , f_2 = 1

cos \lambda = \Big [\dfrac{(0\times -1)+(0\times 0) + (1\times 1) }{\sqrt{(0^2+0^2+1^2)+((-1)^2+0^2+1^2) }} \Big]

cos \ \lambda = \dfrac{1}{\sqrt{2}}

Also, to find the angle \phi between the stress [001] & normal slip plane [111]

Then;

cos \  \phi = \Big [\dfrac{d_1d_3+e_1e_3+f_1f_3}{\sqrt{(d_1^2+e_1^2+f_1^2)+(d_3^2+e_3^2+f_3^2) }} \Big]

replacing their values;

i.e d_1 = 0 ,e_1 = 0 f_1 =  1 & d_3 = 1 , e_3 = 1 , f_3 = 1

cos \  \phi= \Big [ \dfrac{ (0 \times 1)+(0 \times 1)+(1 \times 1)} {\sqrt {(0^2+0^2+1^2)+(1^2+1^2 +1^2)} } \Big]

cos \phi= \dfrac{1} {\sqrt{3} }

However, the critical resolved SS(shear stress) \mathbf{\tau_c} can be computed using the formula:

\tau_c = (\sigma )(cos  \phi )(cos \lambda)

where;

applied tensile stress \sigma = 13.9 MPa

∴

\tau_c =13.9\times (  \dfrac{1}{\sqrt{2}} )( \dfrac{1}{\sqrt{3}})

\mathbf{\tau_c =5.675 \ MPa}

3 0
3 years ago
Q.14
Kay [80]

Answer:

A. optical isolation

Explanation:

well I can't really give a good explanation because I also saw the same question in my exams and option A was the correct answer

6 0
3 years ago
A gas turbine operates with a regenerator and two stages of reheating and intercooling. Air enters this engine at 14 psia and 60
Rzqust [24]

Answer:

flow(m) = 7.941 lbm/s

Q_in = 90.5184 Btu/lbm

Q_out = 56.01856 Btu/lbm

Explanation:

Given:

- T_1 = 60 F = 520 R

- T_6 = 940 = 1400 R

- Heat ratio for air k = 1.4

- Compression ratio r = 3

- W_net,out = 1000 hp

Find:

mass flow rate of the air

rates of heat addition and rejection

Solution:

- Using ideal gas relation compute T_2, T_4, T_10:

                     T_2 = T_1 * r^(k-1/k)

                     T_2 = T_4 = T_10 = 520*3^(.4/1.4) = 711.744 R

- Using ideal gas relation compute T_7, T_5, T_9:

                     T_7 = T_6 * r^(-k-1/k)

                     T_7 = T_5 = T_9 = 1400*3^(-.4/1.4) = 1022.84 R

- The mass flow rate is obtained by:

                     flow(m) = W_net,out / 2*c_p*(1400-1022.84-711.744+520)

                     flow(m) = 1000*.7068 / 2*0.24*(1400-1022.84-711.744+520)

                     flow(m) = 7.941 lbm/s

- The heat input is as follows:

                     Q_in = c_p*(T_6 - T_5)

                     Q_in = 0.24*(1400 - 1022.84)

                     Q_in = 90.5184 Btu/lbm

- The heat output is as follows:

                     Q_out = c_p*(T_10 - T_1)

                     Q_out = 0.24*(711.744 - 520)

                    Q_out = 56.01856 Btu/lbm

                                           

                     

5 0
3 years ago
Other questions:
  • There are 20 forging presses in the forge shop of a small company. The shop produces batches of forgings requiring a setup time
    10·1 answer
  • 3. (9 points) A square-thread power screw is used to raise or lower the basketball board in a gym, the weight of which is W = 10
    12·1 answer
  • A solid steel shaft has to transmit 100 kW at 160 RPM. Taking allowable shear stress at 70 Mpa, find the suitable diameter of th
    15·1 answer
  • An air-conditioning system operates at a total pressure of 1 atm and consists of a heating section and a humidifier that supplie
    15·1 answer
  • Assume, X Company Limited (XCL) is one of the leading 4th generation Life Insurance
    9·2 answers
  • Based on the following passage, why might the government use the U.S. Army Corps of Engineers to undertake hydroelectric power p
    14·1 answer
  • What have you learned about designing solutions? How does this apply to engineering? Think of some engineering solutions that st
    15·1 answer
  • 2.
    7·1 answer
  • Pointttttttttttttssssssssssss
    12·1 answer
  • Valorant Or Csgo? which is best in your opinion?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!