Advertisement

05.04.2008 at 07:32AM PDT, ID: 23374918
[x]
Attachment Details

What Am I Missing?

Asked by IssacharMan in Java Programming Language, New to Java Programming

Tags:

If I wanted to make the words in the window reverse when the Reverse button is pressed, would I need to create a separate method?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
public class MemoSaver extends JFrame implements ActionListener
{
	public static final int WIDTH = 600;
	public static final int HEIGHT = 300;
	public static final int LINES = 10;
	public static final int CHAR_PER_LINE = 40;
 
	private JTextArea theText;
	private String memo1 = "No Memo 1.";
	private String memo2 = "No Memo 2.";
 
	public MemoSaver()
	{
		setSize(WIDTH, HEIGHT);
		addWindowListener(new WindowDestroyer());
		setTitle("MemoSaver");
		Container contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());
 
		JPanel buttonPanel = new JPanel();
		buttonPanel.setBackground(Color.WHITE);
		buttonPanel.setLayout(new GridLayout(3, 2));
		JButton memo1Button = new JButton("Save Memo 1");
		memo1Button.addActionListener(this);
		buttonPanel.add(memo1Button);
		JButton memo2Button = new JButton("Save Memo 2");
		memo2Button.addActionListener(this);
		buttonPanel.add(memo2Button);
		JButton clearButton = new JButton("Clear");
		clearButton.addActionListener(this);
		buttonPanel.add(clearButton);
		JButton get1Button = new JButton("Get Memo 1");
		get1Button.addActionListener(this);
		buttonPanel.add(get1Button);
		JButton get2Button = new JButton("Get Memo 2");
		get2Button.addActionListener(this);
		buttonPanel.add(get2Button);
		JButton exitButton = new JButton("Exit");
		exitButton.addActionListener(this);
		buttonPanel.add(exitButton);
		JButton nameButton = new JButton("My Name");
		nameButton.addActionListener(this);
		buttonPanel.add(nameButton);
		JButton infoButton = new JButton("My Info");
		infoButton.addActionListener(this);
		buttonPanel.add(infoButton);
		JButton reverseButton = new JButton("Reverse");
		reverseButton.addActionListener(this);
		buttonPanel.add(reverseButton);
		contentPane.add(buttonPanel, BorderLayout.SOUTH);
 
		JPanel textPanel = new JPanel();
		textPanel.setBackground(Color.BLUE);
		theText = new JTextArea(LINES, CHAR_PER_LINE);
		theText.setBackground(Color.WHITE);
		textPanel.add(theText);
		contentPane.add(textPanel, BorderLayout.CENTER);
	}
 
	public void actionPerformed(ActionEvent e)
	{
		String actionCommand = e.getActionCommand();
		if (actionCommand.equals("Save Memo 1"))
			memo1 = theText.getText();
		else if (actionCommand.equals("Save Memo 2"))
			memo2 = theText.getText();
		else if (actionCommand.equals("Clear"))
			theText.setText("");
		else if (actionCommand.equals("Get Memo 1"))
			theText.setText(memo1);
		else if (actionCommand.equals("Get Memo 2"))
			theText.setText(memo2);
		else if (actionCommand.equals("My Name"))
			JOptionPane.showMessageDialog(null, "Jackson Johnson");
		else if (actionCommand.equals("My Info"))
			theText.setText("Jackson Johnson - myemail@domain.com");
		else if (actionCommand.equals("Exit"))
			System.exit(0);
		else
			theText.setText("Error in memo interface");
		}
 
		public static void main(String[] args)
		{
			MemoSaver guiMemo = new MemoSaver();
			guiMemo.setVisible(true);
		}
 
	}
[+][-]05.04.2008 at 07:36AM PDT, ID: 21495771

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Java Programming Language, New to Java Programming
Tags: Java
Sign Up Now!
Solution Provided By: CEHJ
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.04.2008 at 07:56AM PDT, ID: 21495836

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628