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
If a heat engine has an efficiency of 30% and its power output is 600 W, what is the rate of heat input from the combustion phas
jarptica [38.1K]

Answer:

The heat input from the combustion phase is 2000 watts.

Explanation:

The energy efficiency of the heat engine (\eta), no unit, is defined by this formula:

\eta = \frac{\dot W}{\dot Q} (1)

Where:

\dot Q - Heat input, in watts.

\dot W - Power output, in watts.

If we know that \dot W = 600\,W and \eta = 0.3, then the heat input from the combustion phase is:

\eta = \frac{\dot W}{\dot Q}

\dot Q = \frac{\dot W}{\eta}

\dot Q = \frac{600\,W}{0.3}

\dot Q = 2000\,W

The heat input from the combustion phase is 2000 watts.

8 0
3 years ago
In a website browser address bar, what does “www” stand for?
Ludmilka [50]

Answer:

www stands for world wide web

Explanation:

It will really help you thank you.

3 0
3 years ago
About ceramics: Only can be optically opaque or semi-transparent. a) True b)-False
julia-pushkina [17]

Answer: True

Explanation: Ceramics have the property that when the band gap present between the atoms are larger than the light energy then the tend to become opaque because the light scattering is caused . They also show the property of being translucent when there are chances of the light to get a path through the surface of ceramic so they get the light at some parts e.g.porcelain .Therefore the statement given is true that ceramics can be optically opaque or semi-transparent(translucent).

6 0
3 years ago
: Câu nào dưới đây thể hiện sự thiếu tự chủ?
sukhopar [10]

Answer:

thành thật mà nói bởi vì cách những chiếc lá đang chuyển và cách mặt trời chiếu sáng.

3 0
3 years ago
As a general rule of thumb, in-line engines are easier to work on than the other cylinder arrangements.
siniylev [52]

Answer:

The general rule of thumb is that the SMALLER a substance's atoms and the STRONGER the bonds, the harder the substance. Two of the strongest forms of chemical bonds are the ionic and covalent bonds.

Explanation:

5 0
3 years ago
Other questions:
  • Water at 20 bar and 400 C enters a turbine operating at steady state and exits at 1.5 bar. Stray heat transfer and kinetic and p
    14·1 answer
  • Select the correct answer.
    12·2 answers
  • What is torque and how does it work?
    14·2 answers
  • Consider a circuit element, with terminals a and b, that has vab= -12V and iab= 3A. Over a period of 2 seconds, how much charge
    8·1 answer
  • Technician A says that the enable criteria are the criteria that must be met before the PCM completes a monitor test. Technician
    8·1 answer
  • (Blank) welding involves manual welding with equipment anomalously controls one or more of the windy conditions while (blank) we
    7·1 answer
  • An excavation is at risk for cave-in and water accumulation because of the excess soil that has accumulated. What type of excava
    8·2 answers
  • A __________ defines the area of land that will supply water to a stream.
    9·1 answer
  • A logic circuit with 3 gates and 2 inputs. The circuit will be read from the final output to the inputs.
    9·1 answer
  • Which of the following is NOT associated with Urban Sprawl?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!