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
The waffle slab is: a) the two-way concrete joist framing system. b) a one-way floor and roof framing system. c) the one-way con
GREYUIT [131]

Answer:

a) the two-way concrete joist framing system

Explanation:

A waffle slab is also known as ribbed slab, it is a slab which as waffle like appearance with holes beneath. It is adopted in construction projects that has long length, length more than 12m. The waffle slab is rigid, therefore it is used in building that needs minimal vibration.

4 0
3 years ago
There have been many attempts to manufacture and market plastic bicycles. All have been too flexible and soft. Which design-limi
Sladkaya [172]

Answer:

The design-limiting property that insufficiently large is the elastic modulus (Young modulus)

Explanation:

Plastic usually have a relatively low elastic modulus, this couses the material to deform too much under stress. In the case of a bicycle, a little weight you put on it or little bumps will cause the bicycle to deform too much.

5 0
3 years ago
Who works alongside and assists the engineers?
nika2105 [10]

Answer:

<u>Assistants</u><u> </u><u>works alongside and assists the engineers.</u>

5 0
3 years ago
4. The instant the ignition switch is turned to the start position,
geniusboy [140]

Answer:

D. Both pull-in and hold-in windings are energized.

Explanation:

The instant the ignition switch is turned to the start position, "Both pull-in and hold-in windings are energized." This is because the moment the ignition switch is turned to the start position, voltage passes through to the S terminal of the solenoid.

The hold-in winding is attached to the case of the solenoid. Similarly, the pull-in winding is also attached to the starter motor. Thereby, the current will move across both windings by getting energized to generate a strong magnetic field.

4 0
2 years ago
This is it dont anwser this is for my other account
Nezavi [6.7K]

Answer:

thanks for the poiunts

Explanation:

6 0
3 years ago
Other questions:
  • Air is compressed in a piston-cylinder device. List three examples of irreversibilities that could occur
    13·1 answer
  • How do you calculate the dynamic lift in an aeroplane?
    5·1 answer
  • An MRI technician moves his hand from a region of very low magnetic field strength into an MRI scanner’s 2.00 T field with his f
    5·1 answer
  • Both equilibrium equations and constitutive models are needed to solve statically indeterminate problems. a)- True b)-False
    13·1 answer
  • Pointssss 100 and brainliest :)
    5·1 answer
  • Hiiiiiiiii<br> jhajwjne f f g. g g tnnjzjnsnsnend f najjwne d f nskiaksjsjsjksm
    5·1 answer
  • Name the four ways in which heat is transferred from a diesel engine
    7·1 answer
  • A benefit to using the medium the author used in "Great Rock and Roll
    12·2 answers
  • Explain the use of a vacuum gauge.
    15·1 answer
  • Does anyone know the answer to this
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!