Assignment This lab is designed to have students become fami

Assignment: This lab is designed to have students become familiar with advanced GUI concepts, such as JTextAreas, JLists, and JComboBoxes. It is also designed to provide a bit more practice with Object Serialization. Finally, it is written in such a way as to be functionally simple, but provide less direct guidance as a problem solving test. For this lab, you have been contracted to write simple color word, an ambitious competitor against Microsoft Word. Unfortunately, as your company only hired you, and have yet to offer you payment, they are unlikely to survive the free market economy. For your GUI, please create the below GUI. It is made of a JTextArea in the center, two buttons, a JList for background colors, a JComboBox for foreground colors, and a bunch of panels. The size I used is 600 by 600. but you do not need to use this size. Note that on the JTextArea, you SHOULD use setPreferredSize(new Dimension(300,500) to set a size for the TextArea. Finally, be sure to have a scroll pane on the TextArea When you select a new background color, the space around the text area should change. Foreground colors should change the color of the text area, as shown:

Solution

Solution:

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import java.util.logging.*;

import javax.swing.*;

public class NotPad extends JPanel implements ActionListener

{

    protected JTextArea textArea;

    JFileChooser fileChoose;

    public NotPad()

{

        super(new BorderLayout());

        fileChoose = new JFileChooser();

        textArea = new JTextArea(5, 25);

        textArea.setEditable(true);

        JScrollPane scrollPane = new JScrollPane(textArea);

        setPreferredSize(new Dimension(300, 500));

        add(scrollPane, BorderLayout.CENTER);

        JPanel panel = new JPanel();

        add(panel, BorderLayout.SOUTH);

        JButton SaveButton = new JButton(\"Save\");

        JButton ResetButton = new JButton(\"Reset\");

        SaveButton.setActionCommand(\"save\");

        ResetButton.setActionCommand(\"reset\");

        SaveButton.addActionListener(this);

        ResetButton.addActionListener(this);

        QuitButton.addActionListener(this);


        panel.add(SaveButton);

        panel.add(ResetButton);

    }

    private static void GUI()

{

        JFrame frame = new JFrame(\"Sample Color Word\");

      

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.add(new NotPad());

        frame.setSize(350, 250);


        frame.pack();

        frame.setVisible(true);

    }

    public void actionPerformed(ActionEvent e)

{

        if (\"save\".equals(e.getActionCommand())) {

            if (textArea.getText().equals(\"\")) {

                JOptionPane.showMessageDialog(this,\"Please Enter Some Text\",\"No Text Error!\", JOptionPane.ERROR_MESSAGE);

            } else {

                int returnVal = fileChoose.showSaveDialog(NotPad.this);

                if (returnVal == JFileChooser.APPROVE_OPTION) {

                    FileWriter fileWriter = null;

                    try {

                        String string = textArea.getText();

                        StringReader stringReader = new StringReader(string);

                        BufferedReader bufferedReader = new BufferedReader(stringReader);

                        File file = fileChoose.getSelectedFile();

                        System.out.println(file.getName());

                        fileWriter = new FileWriter(file);

                        BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

                        for (String line = bufferedReader.readLine();

                             line != null;

                             line = bufferedReader.readLine())

                        {

                            bufferedWriter.write(line);

                            bufferedWriter.newLine();

                        }

                        bufferedReader.close();

                        bufferedWriter.close();

                    } catch (IOException ex) {

                        Logger.getLogger(NotPad.class.getName()).log(Level.SEVERE, null, ex);

                    } finally {

                        try {

                            fileWriter.close();

                        } catch (IOException ex) {

                            Logger.getLogger(NotPad.class.getName()).log(Level.SEVERE, null, ex);

                        }

                    }

                }

            }

        } else if (\"reset\".equals(e.getActionCommand())) {

            textArea.setText(\"\");

        } else {

            System.exit(0);

        }

    }


//Main Function

    public static void main(String[] args) {

        //Set Look and Feel to Nimbus

        try

        {

            UIManager.setLookAndFeel(\"com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel\");

        }

        catch(Exception e){

        }

//creating and showing this application\'s GUI.

        javax.swing.SwingUtilities.invokeLater(new Runnable() {

            public void run() {

                GUI();

            }

        });

    }

}

 Assignment: This lab is designed to have students become familiar with advanced GUI concepts, such as JTextAreas, JLists, and JComboBoxes. It is also designed
 Assignment: This lab is designed to have students become familiar with advanced GUI concepts, such as JTextAreas, JLists, and JComboBoxes. It is also designed
 Assignment: This lab is designed to have students become familiar with advanced GUI concepts, such as JTextAreas, JLists, and JComboBoxes. It is also designed
 Assignment: This lab is designed to have students become familiar with advanced GUI concepts, such as JTextAreas, JLists, and JComboBoxes. It is also designed

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site