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
Milk has a density of as much as 64.6 lb/ft3. What is the gage pressure at the bottom of the straw 6.1 inches deep in the milk?
gregori [183]

Answer:

Explanation:

1 inch is 0.0833333feet

6.1 inches is 0.5083 feet

Density = mass/volume

64.6 = mass/0.50833

mass = 64.6 x 0.5083 =32.83618lb

3 0
3 years ago
I want to cancel my membership
Dennis_Churaev [7]
1. Go to settings 2. Press on your Apple ID 3. Press on subscriptions then turn them off.
5 0
2 years ago
What is the potiental energy of a 3 kg ball that is on the ground
Llana [10]

Answer:

147.15

Explanation:

147.15 is the answer

8 0
2 years ago
Tensile Strength (MPa) Number-Average Molecular Weight (g/mol)
IceJOKER [234]

Answer:

\mathbf{T_{S \infty } \ \approx 215.481 \ MPa}

\mathbf{M_n = 49163.56431  \ g/mol }

Explanation:

The question can be well structured in a table format as illustrated below:

Tensile Strength (MPa)            Number- Average Molecular Weight  (g/mol)

82                                                  12,700

156                                                 28,500

The tensile strength and number-average molecular weight for two polyethylene materials given above.

Estimate the number-average molecular weight that is required to give a tensile strength required above. Using the data given find TS (infinity) in MPa.

<u>SOLUTION:</u>

We know that :

T_S = T_{S \infty} - \dfrac{A}{M_n}

where;

T_S = Tensile Strength

T_{S \infty} = Tensile Strength (Infinity)

M_n = Number- Average Molecular Weight  (g/mol)

SO;

82= T_{S \infty} - \dfrac{A}{12700} ---- (1)

156= T_{S \infty} - \dfrac{A}{28500} ---- (2)

From equation (1) ; collecting the like terms; we have :

T_{S \infty} =82+ \dfrac{A}{12700}

From equation (2) ; we have:

T_{S \infty} =156+ \dfrac{A}{28500}

So; T_{S \infty} = T_{S \infty}

Then;

T_{S \infty} =82+ \dfrac{A}{12700} =156+ \dfrac{A}{28500}

Solving by L.C.M

\dfrac{82(12700) + A}{12700} =\dfrac{156(28500) + A}{28500}

\dfrac{1041400 + A}{12700} =\dfrac{4446000 + A}{28500}

By cross multiplying ; we have:

({4446000 + A})*  {12700} ={28500} *({1041400 + A})

(5.64642*10^{10} + 12700A) =(2.96799*10^{10}+ 28500A)

Collecting like terms ; we have

(5.64642*10^{10} - 2.96799*10^{10} ) =( 28500A- 12700A)

2.67843*10^{10}  = 15800 \ A

Dividing both sides by 15800:

\dfrac{ 2.67843*10^{10} }{15800} =\dfrac{15800 \ A}{15800}

A = 1695208.861

From equation (1);

82= T_{S \infty} - \dfrac{A}{12700} ---- (1)

Replacing A = 1695208.861 in the above equation; we have:

82= T_{S \infty} - \dfrac{1695208.861}{12700}

T_{S \infty}= 82 + \dfrac{1695208.861}{12700}

T_{S \infty}= \dfrac{82(12700) +1695208.861 }{12700}

T_{S \infty}= \dfrac{1041400 +1695208.861 }{12700}

T_{S \infty}= \dfrac{2736608.861 }{12700}

\mathbf{T_{S \infty } \ \approx 215.481 \ MPa}

From equation(2);

156= T_{S \infty} - \dfrac{A}{28500} ---- (2)

Replacing A = 1695208.861 in the above equation; we have:

156= T_{S \infty} - \dfrac{1695208.861}{28500}

T_{S \infty}= 156 + \dfrac{1695208.861}{28500}

T_{S \infty}= \dfrac{156(28500) +1695208.861 }{28500}

T_{S \infty}= \dfrac{4446000 +1695208.861 }{28500}

T_{S \infty}= \dfrac{6141208.861}{28500}

\mathbf{T_{S \infty } \ \approx 215.481 \ MPa}

We are to also estimate the number- average molecular weight that is required to give a tensile strength required above.

If the Tensile Strength (MPa) is 82 MPa

Definitely the average molecular weight will be = 12,700 g/mol

If the Tensile Strength (MPa) is 156 MPa

Definitely the average molecular weight will be = 28,500 g/mol

But;

Let us assume that the Tensile Strength (MPa) = 181 MPa for example.

Using the same formula:

T_S = T_{S \infty} - \dfrac{A}{M_n}

Then:

181 = 215.481- \dfrac{1695208.861 }{M_n}

Collecting like terms ; we have:

\dfrac{1695208.861 }{M_n} = 215.481-  181

\dfrac{1695208.861 }{M_n} =34.481

1695208.861= 34.481 M_n

Dividing both sides by 34.481; we have:

M_n = \dfrac{1695208.861}{34.481}

\mathbf{M_n = 49163.56431  \ g/mol }

5 0
3 years ago
I'm so confused to this question <br>What is the difference between Science and Engineering? ​
muminat

Explanation:

Science is the body of knowledge that explores the physical and natural world. Engineering is the application of knowledge in order to design, build and maintain a product or a process that solves a problem and fulfills a need (i.e. a technology).

4 0
3 years ago
Read 2 more answers
Other questions:
  • There is a proposal in Brooklyn to construct a new mid-rise apartment building on a vacant lot at the intersection of Avenue A a
    8·1 answer
  • Complex poles cmd zeros. Sketch the asymptotes of the Bode plot magnitude and phase for each of the listed open-loop mmsfer fuoc
    10·1 answer
  • Write a program that uses a function called Output_Array_Info. Output_Array_Info Properties: Input Parameters: 1. A pointer to a
    15·1 answer
  • A large plate is fabricated from a steel alloy that has a plane strain fracture toughness of 78 MPa (70.98 ksi). If the plate is
    7·1 answer
  • What type of drawing would civil engineers use if they needed to show an
    11·1 answer
  • If a toy car covers a distance of 42m in 7sec, what is it’s speed
    9·2 answers
  • Explain the underlying physical reason why when we conduct various heat treatments on 1018 steel we expect the modulus of elasti
    8·1 answer
  • A flashed steam geothermal power plant is located where underground hot water is available as saturated liquid at 700 kPa. The w
    14·1 answer
  • In addition to passing an ASE certification test, automotive technicians must have __________ year(s) of on the job training or
    15·1 answer
  • Recall the steps of the engineering design process. Compare and contrast the
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!