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
Thermodynamics fill in the blanks The swimming pool at the local YMCA holds roughly 749511.5 L (749511.5 kg) of water and is kep
Talja [164]

Answer:

95.914\ \text{GJ}

\$272.78

Explanation:

m = Mass of water = 749511.5 kg

c = Specific heat of water = 4182 J/kg ⋅°C

\Delta T = Change in temperature = 80.6-50=30.6^{\circ}\text{F}

Cost of 1 GJ of energy = $2.844

Heat required is given by

Q=mc\Delta T\\\Rightarrow Q=749511.5\times 4182\times 30.6\\\Rightarrow Q=95.914\times 10^9\ \text{J}=95.914\ \text{GJ}

Amount of heat required to heat the water is 95.914\ \text{GJ}.

Cost of heating the water is

95.914\times 2.844=\$272.78

Cost of heating the water to the required temperature is \$272.78.

7 0
2 years ago
What setting do i dry my jordan max arua 2s on in the dryer <br>will mark brainliest
antiseptic1488 [7]
Probably low heat and a longer time. Better sad than sorry
3 0
3 years ago
Which branch of engineering most closely relates to mechanical engineering?
Rus_ich [418]

Answer:

C

Explanation:

I COULD be wrong, i'm not sure but im confident its c

4 0
3 years ago
This manometer is used to measure the difference in water level between the two tanks.
SpyIntel [72]

Answer:

a) True

Explanation:

hope it helps u

3 0
2 years ago
HELP PLEASE!!!!
DaniilM [7]

Answer:

DESCULPA MAS EU NÃO ENTENDI

8 0
2 years ago
Other questions:
  • Use the convolutional integral to find the response of an LTI system with impulse response ℎ(????) and input x(????). Sketch the
    8·1 answer
  • Argon is compressed in a polytropic process with n=1.2 from 120 kPa and 10 °C to 800 kPa in a piston cylinder device. Determine:
    11·1 answer
  • Heat in the amount of 100 kJ is transferred directly from a hot reservoir at 1200 K to a cold reservoir at 600 K. Calculate the
    15·1 answer
  • It is possible to have liquid water at 200°C. a)-True b)- False
    14·1 answer
  • Why did fprtmiu78t7ty87uhyu
    12·1 answer
  • PLS HURRYY!!!<br> Look at the image below
    10·1 answer
  • Could I please get help with this​
    11·1 answer
  • 1. In order to minimize hazards, what should you do before starting a job
    10·2 answers
  • What is equation for surface area?
    9·1 answer
  • A. How is a decision matrix useful during the
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!