Marie Jeanne Thibault

Greenhorn
+ Follow
since Nov 15, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Marie Jeanne Thibault

I'm really stuck. I only want this program accept integer input. Any other input like a char I want it to display a message that it is the wrong type of input and display the input in question. Here is what I've got so far. Any help would be appreciated.
Thanks,
Marie
//ExceptDemo1b.java
public class ExceptDemo1b
{
//Main Method with three arguments
//args[0]: operator
//args[1]: operand1
//args[2]: operand2
public static void main(String[] args)
{
//Declare and initialize variables
int result = 0;
int operand1 = 0;
int operand2 = 0;
if (args.length != 3)
{
System.out.println("Usage: java Calculator operator operand1 operand2");
System.exit(0);
}
if(((operand1 >= 0) || (operand1 < 0)) && ((operand2 >= 0) || (operand2 < 0)))
{
operand1 = Integer.parseInt(args[1]);
operand2 = Integer.parseInt(args[2]);
switch (args[0].charAt(0))
{
case '+': result = Integer.parseInt(args[1]) +
Integer.parseInt(args[2]);
break;
case '-': result = Integer.parseInt(args[1]) -
Integer.parseInt(args[2]);
break;

case '*': result = Integer.parseInt(args[1]) *
Integer.parseInt(args[2]);
break;
case '/': result = Integer.parseInt(args[1]) /
Integer.parseInt(args[2]);
}
//Display the result
System.out.println(args[1]+ ' ' +args[0]+ ' ' +args[2]+ "=" +result);
}
else
{
System.out.println("Wrong input ");
System.exit(0);
}

}
}
21 years ago
Hi Everyone,
I'm having trouble with the last part of my code. No matter what input I enter, the "out of bounds" message is displayed. I'm thinking it's something in the actionPerformed class. I've agonized over this one for about a week now.
Thanks,
Marie
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ArrayDemo extends JFrame implements ActionListener
{
//Declare two textfields
private JTextField jtfIndex = new JTextField(8);
private JTextField jtfElement = new JTextField(8);
private JButton jbtShow = new JButton("Show Element");//Declare "Show Element" button
//Constructor
public ArrayDemo()
{
setTitle("Show Bounds Error");

//Create panel for the textfields
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout (2,2));
p1.add(new JLabel("Array Index"));
p1.add(jtfIndex);
p1.add(new JLabel("Array Element"));
p1.add(jtfElement);

//Create panel for button
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout());
p2.add(jbtShow);
//Set panels in frame
getContentPane().setLayout(new BorderLayout());
getContentPane().add(p1,BorderLayout.CENTER);
getContentPane().add(p2,BorderLayout.SOUTH);
//Register Listener
jbtShow.addActionListener(this);
}

//Main Method
public static void main(String[] args)
{
int key;
int[] list = new int[100];
for(int i = 0; i < list.length; i++)
{
list[i] = (int)(Math.random() * 100);
}
ArrayDemo frame = new ArrayDemo();
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setSize(230, 120);
}
//The nitty gritty
public void actionPerformed(ActionEvent e)
{
int key = (Integer.parseInt(jtfIndex.getText()));
int[] list = new int[100];
int result = linearSearch(key, list);
if (e.getSource() == jbtShow)
if(result != -1)
jtfElement.setText(String.valueOf(result));
else
jtfElement.setText("Out of Bounds");

}
public static int linearSearch(int key, int[] list)
{
for(int i = 0; i < list.length; i++)

if (key == list[i])
return i;
return -1;
}
}
21 years ago
Hi!
Can anyone give me a hint as to why my linear search won't work? When a number is entered in the index textfield and click the show button, that element should be displayed in the element textfield. I get all sorts of exception messages. Anything would be appreciated.
Here's the code:
//ArrayDemo.java

Thanks,
Marie
[ January 31, 2004: Message edited by: Jim Yingst ]
21 years ago
Hi All!
Just a couple of questions. How do I code the keyboard accelerator Ctrl+Alt? I've found lots of stuff on how to code if you're using only one or the other but not both at the same time.
The other question I have has to do with null strings. I've got a "clear" button set up and the actionlistener coded, but what code do I use to make it clear all textfields when clicked?
All suggestions appreciated!
Marie
21 years ago
Hi All,
Before you look at my code, let me warn you that I know it's a mess...I'm suppose to create a very simple calculator that uses command line parameters. I'm not suppose to use any exception handlers but it is suppose to display a message when one of the operands is not an integer or if there are less or more than three args.
I've got all sorts of "if" loops going on. It compiles but is not running properly. Any guidance would be appreciated.
public class ExceptDemo1b
{
//Main Method with three arguments
//args[0]: operator
//args[1]: operand1
//args[2]: operand2
public static void main(String[] args)
{
//Declare and initialize variables
int result = 0;
int operand1 = Integer.parseInt(args[1]);
int operand2 = Integer.parseInt(args[2]);
if (args.length != 3)
{
System.out.println("Usage: java Calculator operator operand1 operand2");
System.exit(0);
}
if((operand1 >= 0) || (operand1 < 0))
{
switch (args[0].charAt(0))
{
case '+': result = Integer.parseInt(args[1]) +
Integer.parseInt(args[2]);
break;
case '-': result = Integer.parseInt(args[1]) -
Integer.parseInt(args[2]);
break;

case '*': result = Integer.parseInt(args[1]) *
Integer.parseInt(args[2]);
break;
case '/': result = Integer.parseInt(args[1]) /
Integer.parseInt(args[2]);
}
//Display the result
System.out.println(args[1]+ ' ' +args[0]+ ' ' +args[2]+ "=" +result);
}
else
{
System.out.println("Wrong input " + operand1);
System.exit(0);
}
if ((operand2 >= 0) || (operand2 < 0))

switch (args[0].charAt(0))
{
case '+': result = Integer.parseInt(args[1]) +
Integer.parseInt(args[2]);
break;
case '-': result = Integer.parseInt(args[1]) -
Integer.parseInt(args[2]);
break;

case '*': result = Integer.parseInt(args[1]) *
Integer.parseInt(args[2]);
break;
case '/': result = Integer.parseInt(args[1]) /
Integer.parseInt(args[2]);
}
//Display the result
System.out.println(args[1]+ ' ' +args[0]+ ' ' +args[2]+ "=" +result);


System.out.println("Wrong input " + operand2);
System.exit(0);
}
}
Thanks,
Marie
21 years ago
Thanks Karl, worked like a charm.
Marie
21 years ago
Hi Everyone,
I'm wondering if you can help me with this...I want a message to be displayed if args[1] and args[2] are anything but integers. I know my "if" statements are not right but that's what I want it to do. How do I make this work? Here's my code...
//ExceptDemo1a.java
public class ExceptDemo1a
{
//Main Method with three arguments
//args[0]: operator
//args[1]: operand1
//args[2]: operand2
public static void main(String[] args)
{
//Declare and initialize variables
int result = 0;
int operand1 = 0;
int operand2 = 0;
if(operand1 != int)
{
operand1 = new Integer(args[1]).intValue();
try
{
switch (args[0].charAt(0))
{
case '+': result = Integer.parseInt(args[1]) +
Integer.parseInt(args[2]);
break;
case '-': result = Integer.parseInt(args[1]) +
Integer.parseInt(args[2]);
break;

case '*': result = Integer.parseInt(args[1]) +
Integer.parseInt(args[2]);
break;
case '/': result = Integer.parseInt(args[1]) +
Integer.parseInt(args[2]);
}
}
catch(Exception ex1)
{
System.out.println("Input must be an integer");
}
}

else if(operand2 != int)
{
operand2 = new Integer(args[2]).intValue();
try
{
switch (args[0].charAt(0))
{
case '+': result = Integer.parseInt(args[1]) +
Integer.parseInt(args[2]);
break;
case '-': result = Integer.parseInt(args[1]) +
Integer.parseInt(args[2]);
break;

case '*': result = Integer.parseInt(args[1]) +
Integer.parseInt(args[2]);
break;
case '/': result = Integer.parseInt(args[1]) +
Integer.parseInt(args[2]);
}
}
catch(Exception ex2)
{
System.out.println("Input must be an integer");
}
}

//Display the result
System.out.println(args[1]+ ' ' +args[0]+ ' ' +args[2]+ "=" +result);
}
}

Any help would sure be appreciated!!!
Thanks,
Marie
21 years ago
Thanks, it worked!
Marie
21 years ago
Hey Everyone,
I'm not sure why but I can't seem to get my head around making comboboxes work. Everything works up to when I try to transfer a selected item from the combobox to the text field. What am I not doing?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestStore extends JFrame implements ActionListener
{
//Declare the textfield, textarea, and combobox
public JTextField jtfName;
public JTextArea jtaArea;
public JComboBox jcboBox;
public JButton jbtStore;
//Main Method
public static void main(String[] args)
{
TestStore frame = new TestStore();
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setSize(500,300);
}
//Constructor
public TestStore()
{
setTitle("Test Store Button");
setBackground(Color.yellow);
setForeground(Color.white);

//Create panel p1 for textfield, area and combobox
JPanel p1 = new JPanel();
jcboBox = new JComboBox();
p1.setLayout(new FlowLayout());
p1.add(jtfName = new JTextField(15));
p1.add(jtaArea = new JTextArea(15, 15));
p1.add(jcboBox);
jtfName.setEditable(true);
//Create panel p2 for Store button
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout());
p2.add(jbtStore = new JButton("Store"));
//Set Panels in frame
getContentPane().setLayout(new BorderLayout());
getContentPane().add(p1,BorderLayout.CENTER);
getContentPane().add(p2,BorderLayout.SOUTH);
//Register Listeners
jbtStore.addActionListener(this);
jcboBox.addActionListener(this);
}

//Transfer text from Field to Area and Combobox
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == jbtStore)
{
String name = (jtfName.getText());
//Set text in Area and Combobox
jtaArea.append(name + "\n");
jcboBox.addItem(name);
}
else if(e.getSource() == jcboBox);
{
String name = (String) jcboBox.getSelectedItem();
jtfName.add(name);
}
}
}
Thanks!
Marie
21 years ago
Hi!
Can anyone see where I went off the rails with this one? I can't seem to get the windows to show up. Here's my code.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;
public class MultiWin extends JApplet implements ActionListener
{
private JButton jbtCalc;
private JButton jbtMort;

//Create the frames to hold the calculator and mortgage calculators
JFrame calcFrame = new JFrame();
JFrame mortFrame = new JFrame();
//Construct the frame
public void init()
{
//Place the buttons in the frame
getContentPane().setLayout(new FlowLayout());
getContentPane().add(jbtCalc = new JButton("Simple Calculator"));
getContentPane().add(jbtMort = new JButton("Mortgage"));
//Register Listeners
jbtCalc.addActionListener(this);
jbtMort.addActionListener(this);
}
//Handle the buttons
public void actionPerformed(ActionEvent e)
{
String arg = e.getActionCommand();
if (e.getSource() instanceof JButton)
if("Simple Calculator".equals(arg))
{
jbtCalc.setText("Hide Simple Calculator");
calcFrame.pack();
calcFrame.setVisible(true);
}
else if ("Hide Simple Calculator".equals(arg))
{
calcFrame.setVisible(false);
jbtCalc.setText("Simple Calculator");
}
else if("Mortgage".equals(arg))
{
mortFrame.pack();
jbtMort.setText("Hide Mortgage Calculator");
mortFrame.setVisible(true);
}
else if ("Hide Mortgage Calculator".equals(arg))
{
mortFrame.setVisible(false);
jbtMort.setText("Mortgage");
}
}
}
class SimpCalc extends JApplet implements ActionListener
{
// Text fields for Number 1, Number 2, and Result
private JTextField jtfNum1, jtfNum2, jtfResult;
// Buttons "Add", "Subtract", "Multiply" and "Divide"
private JButton jbtAdd, jbtSub, jbtMul, jbtDiv;
// Menu items "Add", "Subtract", "Multiply","Divide" and "Close"
private JMenuItem jmiAdd, jmiSub, jmiMul, jmiDiv, jmiClose;
//Main Method
public void main(String[] args)
{
SimpCalc frame = new SimpCalc();
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
// Default Constructor
public SimpCalc()
{
setTitle("Simple Calculator");
// Create menu bar
JMenuBar jmb = new JMenuBar();

// Add menu "Operation" to menu bar
JMenu operationMenu = new JMenu("Operation");
operationMenu.setMnemonic('O');
jmb.add(operationMenu);
// Add menu "Exit" in menu bar
JMenu exitMenu = new JMenu("Exit");
exitMenu.setMnemonic('E');
jmb.add(exitMenu);
// Add menu items with mnemonics to menu "Operation"
operationMenu.add(jmiAdd= new JMenuItem("Add", 'A'));
operationMenu.add(jmiSub = new JMenuItem("Subtract", 'S'));
operationMenu.add(jmiMul = new JMenuItem("Multiply", 'M'));
operationMenu.add(jmiDiv = new JMenuItem("Divide", 'D'));
exitMenu.add(jmiClose = new JMenuItem("Close", 'C'));
// Set keyboard accelerators
jmiAdd.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
jmiSub.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
jmiMul.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.CTRL_MASK));
jmiDiv.setAccelerator(
KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.CTRL_MASK));
// Panel p1 to hold text fields and labels
JPanel p1 = new JPanel();
p1.setLayout(new FlowLayout());
p1.add(new JLabel("Number 1"));
p1.add(jtfNum1 = new JTextField(3));
p1.add(new JLabel("Number 2"));
p1.add(jtfNum2 = new JTextField(3));
p1.add(new JLabel("Result"));
p1.add(jtfResult = new JTextField(4));
jtfResult.setEditable(false);
// Panel p2 to hold buttons
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout());
p2.add(jbtAdd = new JButton("Add"));
p2.add(jbtSub = new JButton("Subtract"));
p2.add(jbtMul = new JButton("Multiply"));
p2.add(jbtDiv = new JButton("Divide"));
// Add menubar to the frame
setJMenuBar(jmb);

//Add the panels to the frame
getContentPane().setLayout(new BorderLayout());
getContentPane().add(p1, BorderLayout.CENTER);
getContentPane().add(p2, BorderLayout.SOUTH);
// Register listeners
jbtAdd.addActionListener(this);
jbtSub.addActionListener(this);
jbtMul.addActionListener(this);
jbtDiv.addActionListener(this);
jmiAdd.addActionListener(this);
jmiSub.addActionListener(this);
jmiMul.addActionListener(this);
jmiDiv.addActionListener(this);
jmiClose.addActionListener(this);
}
// Handle ActionEvent from buttons and menu items
public void actionPerformed(ActionEvent e)
{
String actionCommand = e.getActionCommand();
// Handle button events
if (e.getSource() instanceof JButton)
{
if ("Add".equals(actionCommand))
calculate('+');
else if ("Subtract".equals(actionCommand))
calculate('-');
else if ("Multiply".equals(actionCommand))
calculate('*');
else if ("Divide".equals(actionCommand))
calculate('/');
}
else if (e.getSource() instanceof JMenuItem)
{
// Handle menu item events
if ("Add".equals(actionCommand))
calculate('+');
else if ("Subtract".equals(actionCommand))
calculate('-');
else if ("Multiply".equals(actionCommand))
calculate('*');
else if ("Divide".equals(actionCommand))
calculate('/');
else if ("Close".equals(actionCommand))
System.exit(0);
}
}
// Calculate and show the result in jtfResult
private void calculate(char operator)
{
// Obtain Number 1 and Number 2
int num1 = (Integer.parseInt(jtfNum1.getText().trim()));
int num2 = (Integer.parseInt(jtfNum2.getText().trim()));
int result = 0;
// Perform selected operation
switch (operator)
{
case '+': result = num1 + num2;
break;
case '-': result = num1 - num2;
break;
case '*': result = num1 * num2;
break;
case '/': result = num1 / num2;
}
// Set result in jtfResult
jtfResult.setText(String.valueOf(result));
}
public class MortCalc extends JApplet implements ActionListener
{
//Declare and create textfields for interest rate
private JTextField jtfAnnualInterestRate = new JTextField();
private JTextField jtfNumOfYears = new JTextField();
private JTextField jtfLoanAmount = new JTextField();
private JTextField jtfMonthlyPayment = new JTextField();
private JTextField jtfTotalPayment = new JTextField();
private JButton jbtComputeMortgage = new JButton("Compute Mortgage");
//Initialize the interface
public void init()
{
//Set properties for the text fields
jtfMonthlyPayment.setEditable(false);
jtfTotalPayment.setEditable(false);
//Align the text Fields
jtfAnnualInterestRate.setHorizontalAlignment(JTextField.RIGHT);
jtfNumOfYears.setHorizontalAlignment(JTextField.RIGHT);
jtfLoanAmount.setHorizontalAlignment(JTextField.RIGHT);
jtfMonthlyPayment.setHorizontalAlignment(JTextField.RIGHT);
jtfTotalPayment.setHorizontalAlignment(JTextField.RIGHT);
//Panel p1 to hold labels and text fields
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout (5,2));
p1.add(new Label("Annual Interest Rate"));
p1.add(jtfAnnualInterestRate);
p1.add(new Label("Number of Years"));
p1.add(new Label("Loan Amount"));
p1.add(jtfLoanAmount);
p1.add(new Label("Monthly Payment"));
p1.add(jtfMonthlyPayment);
p1.add(new Label("Total Payment"));
p1.add(jtfTotalPayment);
p1.setBorder(new TitledBorder("Enter interest rate, year and loan amount"));
//panel p2 holds the button
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout(FlowLayout.RIGHT));
p2.add(jbtComputeMortgage);
//Add the components to the applet
getContentPane().add(p1,BorderLayout.CENTER);
getContentPane().add(p2,BorderLayout.SOUTH);
//Register Listener
jbtComputeMortgage.addActionListener(this);
}
//Handler for the button
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == jbtComputeMortgage)
{
double interest = (Double.valueOf(jtfAnnualInterestRate.getText())).doubleValue();
int year = (Integer.valueOf(jtfNumOfYears.getText())).intValue();
double loan = (Double.valueOf(jtfLoanAmount.getText())).doubleValue();
//Create a mortgage object
double Mortgage;
Mortgage m = new Mortgage(interest, year, loan);
//Display monthly pament and total payment
jtfMonthlyPayment.setText(String.valueOf(m.monthlyPayment()));
jtfTotalPayment.setText(String.valueOf(m.totalPayment()));
}
}
}
}
It won't compile. I debug halfway through but the windows wouldn't show up. Help!
Thanks,
Marie
[ November 29, 2003: Message edited by: Marie Jeanne Thibault ]
21 years ago
Hi Jose,
Wow, looks like I was making it a lot more complicated than it should've been. By the way, I got it (nudge, nudge, wink, wink)...
Thanks again!
21 years ago
Jose, thank you soooo much for helping me out. I've been agonizing over this one for a long time. I won't make the same mistake again.
Marie
21 years ago
Hi,
I'm real new to this so I may be out to lunch but I've noticed that you've left out JFrame in your constructor.
Try: public class MaxAndMin extends JFrame implements ActionListener
Marie
21 years ago
Hi!
Can anyone please help me understand why my panel p1 won't change color?
Thanks,
Lynn
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import java.awt.Color.*;
public class Scroll extends JFrame implements AdjustmentListener
{
//Declare
private JScrollBar jscbHort1, jscbHort2, jscbHort3;

//Main
public static void main(String[] args)
{
Scroll frame = new Scroll();
frame.pack();
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
frame.setSize(400, 250);
frame.setVisible(true);
}
//Default constructor
public Scroll()
{
setTitle("Exercise 9.9: Use Scroll Bars");
//Create panel to hold the color display
JPanel p1 = new JPanel();
p1.add(new JLabel("Show Colors", SwingConstants.CENTER));
p1.setLayout(new GridLayout(1, 1));
//Create second panel that holds the scrollbars
JPanel p2 = new JPanel();
p2.setLayout(new GridLayout(3, 1));
p2.setBorder(new TitledBorder("Choose Colors"));
p2.add(new JLabel("Red"));
p2.add(jscbHort1 = new JScrollBar());
jscbHort1.setValues(0,50,0,255);
p2.add(new JLabel("Green"));
p2.add(jscbHort2 = new JScrollBar());
jscbHort2.setValues(0,50,0,255);
p2.add(new JLabel("Blue"));
p2.add(jscbHort3 = new JScrollBar());
jscbHort3.setValues(0,50,0,255);
jscbHort1.setOrientation(Adjustable.HORIZONTAL);
jscbHort2.setOrientation(Adjustable.HORIZONTAL);
jscbHort3.setOrientation(Adjustable.HORIZONTAL);
//Add panels to frame
getContentPane().setLayout(new BorderLayout());
getContentPane().add(p1, BorderLayout.CENTER);
getContentPane().add(p2, BorderLayout.SOUTH);
//Register the listeners
jscbHort1.addAdjustmentListener(this);
jscbHort2.addAdjustmentListener(this);
jscbHort3.addAdjustmentListener(this);
}

//Handle the scroll bar adjustment actions
public void adjustmentValueChanged(AdjustmentEvent e)
{
JPanel p1 = new JPanel();
if(e.getSource() == jscbHort1)
{
Color c = new Color(jscbHort1.getValue(), jscbHort2.getValue(), jscbHort3.getValue());
p1.setForeground(Color.red);
p1.repaint();
}
else if(e.getSource() == jscbHort2)
{
Color c = new Color(jscbHort1.getValue(), jscbHort2.getValue(), jscbHort3.getValue());
p1.setForeground(Color.green);
p1.repaint();
}
else if(e.getSource() == jscbHort3)
{
Color c = new Color(jscbHort1.getValue(), jscbHort2.getValue(), jscbHort3.getValue());
p1.setForeground(Color.blue);
p1.repaint();
}
}
}
21 years ago
Hi Everyone,
I'm new to Java and this site. Can anyone out there please help me with my code? The program compiles but the province and postal code won't transfer on to the text area. I also get a whole bunch of exceptions. I'm sure the problem lies in the actionPerformed method but I've run out of ideas. I've figured out that I don't need an ItemListener for the jcb because I'm not asking it to do anything.
Here's my code.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class UniStore extends JFrame implements ActionListener
{
//Declare
private JTextField jtfName, jtfDept, jtfUni, jtfPost;
private JButton jbtStore;
private JComboBox jcboProv;
private JTextArea jtaArea;
private String[] provName = {"BC", "AB", "SK", "MN", "ON", "QC", "NF",
"PEI", "NB", "NS"};


//Main method
public static void main(String[] args)
{
UniStore frame = new UniStore();
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 300);
frame.setVisible(true);
}
//Constructor
public UniStore()
{
setTitle("Educational Institution");


//Create panel p1
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(3, 2, 5, 5));
p1.add(new JLabel("Name"));
p1.add(jtfName = new JTextField());
p1.add(new JLabel("Department"));
p1.add(jtfDept = new JTextField());
p1.add(new JLabel("University"));
p1.add(jtfUni = new JTextField());

//Create p2

JComboBox jcboProv = new JComboBox(provName);


JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout());
p2.add(new JLabel("Province"));
p2.add(jcboProv = new JComboBox(provName));
p2.add(new JLabel("Postal Code"));
p2.add(jtfPost = new JTextField(10));
//Create p3
JPanel p3 = new JPanel();
p3.setLayout(new FlowLayout(FlowLayout.LEFT));
p3.add(jtaArea = new JTextArea(8,30));
p3.add(jbtStore = new JButton("Store"));
//Set panels in frame
getContentPane().setLayout(new BorderLayout());
getContentPane().add(p1, BorderLayout.NORTH);
getContentPane().add(p2, BorderLayout.WEST);
getContentPane().add(p3, BorderLayout.SOUTH);
//Register Listeners
jbtStore.addActionListener(this);
}
//Transfer the information to the textarea
public void actionPerformed(ActionEvent e)
{

if (e.getSource() == jbtStore)

{
String name = (jtfName.getText());
String dept = (jtfDept.getText());
String uni = (jtfUni.getText());

String post = (jtfPost.getText());


jtaArea.append(name + "\n");
jtaArea.append(dept + "\n");
jtaArea.append(uni + "\n");
jtaArea.append((String)jcboProv.getSelectedItem());
jtaArea.append(post + "\n");
jtaArea.repaint();

}
}
}
21 years ago