Question & Answer: Need this and everything exactly. Thank you!…..

Need this and everything exactly. Thank you!

We are going to re-do the SuperLottoPlus assignment, and turn it into a Java swing application Create a new class called SuperLottoSwing.java that extends JFrame.

Create the GUI Set the window title to “SuperLottoPlus” (10 point)

Create two JPanel objects (north and center panel) (10 point)

Using BorderLayout, set the position of the north and center panel(10 point)

Add 3 JButtons to the north panel: “I’m Feeling Lucky”, “Reset”, and “Print” (10 point)

Made the north panel background color orange (10 point)

Add a text area box (JTextArea) to the center panel (this is where we will display the lotto numbers) (10 point)

When the user clicks the “I’m Feeling Lucky” button: Make the center panel background yellow (10 point)

Display the SuperLotto lottery numbers in the text area box. (10 point)

When the user clicks the “Reset” button, make the center panel background white, and clear the text. (10 point)

When the user clicks the “Print” button, write whatever text is in the center panel to a file called “superlotto.txt” (10 point)

Expert Answer

Java Code
package superlotto.GUI;

import java.awt.BorderLayout;

import java.awt.EventQueue;

import javax.swing.JFrame;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.border.EmptyBorder;

import java.awt.Color;

import javax.swing.JTextArea;

import javax.swing.JButton;

import java.awt.event.ActionListener;

import java.io.File;

import java.io.FileWriter;

import java.io.IOException;

import java.awt.event.ActionEvent;

public class SuperLottoSwing extends JFrame {

private JPanel contentPane;

private JTextArea textArea_lottoNum;

// lotto numbers array.

private String[] lottoNumbers = {“8242632441”, “94638782387”, “23465891643”, “35267459824”,

“18953286794”, “91645278542”, “43675489023”};

/**

* Launch the application.

*/

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

SuperLottoSwing frame = new SuperLottoSwing(“SuperLottoPlus”);

frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the frame.

*/

public SuperLottoSwing(String title) {

this.setTitle(title);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100, 100, 450, 300);

contentPane = new JPanel();

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

contentPane.setLayout(new BorderLayout(0, 0));

setContentPane(contentPane);

JPanel NorthPanel = new JPanel();

NorthPanel.setBackground(Color.ORANGE);

contentPane.add(NorthPanel, BorderLayout.NORTH);

JPanel CenterPanel = new JPanel();

contentPane.add(CenterPanel, BorderLayout.CENTER);

textArea_lottoNum = new JTextArea(5, 20);

textArea_lottoNum.setEditable(false);

CenterPanel.add(textArea_lottoNum);

// Button I am feeling lucky

JButton btn_feelingLucky = new JButton(“I’m Feeling Lucky”);

btn_feelingLucky.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

CenterPanel.setBackground(Color.orange);

for(String num : lottoNumbers)

textArea_lottoNum.setText(textArea_lottoNum.getText()+num+”n”);

}

});

NorthPanel.add(btn_feelingLucky);

//Button Reset

JButton btn_reset = new JButton(“Reset”);

btn_reset.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

CenterPanel.setBackground(Color.decode(“#f0f0f0”)); // setting to default color

textArea_lottoNum.setText(“”);

}

});

NorthPanel.add(btn_reset);

// Button Print

JButton btn_print = new JButton(“Print”);

btn_print.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

printToFile();

}

});

NorthPanel.add(btn_print);

}

/**

* Method to print to file

*/

public void printToFile()

{

if(!(textArea_lottoNum.getText().equals(“”))){

FileWriter fw = null;

try {

fw = new FileWriter(new File(“superlotto.txt”));

for(String num : lottoNumbers)

fw.write(num+”n”); // printing to file

fw.close();

JOptionPane.showMessageDialog(null, “Lotto Numbers printed to file succesfully.”);

}

catch (IOException e1) {

JOptionPane.showMessageDialog(null, “Error in creating the ‘superlotto.txt’ file”, “ERROR”, JOptionPane.ERROR_MESSAGE);

}

}

else

JOptionPane.showMessageDialog(null, “Nothing in Text Area to print”);

}

}

Instructions: Open your java ide create a new project with package name superlotto.GUI and within this package create a new class named SuperLottoSwing after than copy-paste the above code into the class file and run.

OUTPUT

Question & Answer: Need this and everything exactly. Thank you!..... 1

Question & Answer: Need this and everything exactly. Thank you!..... 2

Question & Answer: Need this and everything exactly. Thank you!..... 3

Still stressed from student homework?
Get quality assistance from academic writers!