How to I store and retrieve data for pop up windows in Java?

Store and retrieve data for pop up windows in Java?

Page 1 of 1

2 Replies - 1397 Views - Last Post: 06 August 2008 - 06:13 PM Rate Topic: -----

#1 bizzorg  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-August 08

How to I store and retrieve data for pop up windows in Java?

Post icon  Posted 05 August 2008 - 01:48 PM

/*
 * MortgageFrameCombo2.java
 *
 * Created on July 29, 2008, 8:38 PM
 */

import java.text.NumberFormat;
import java.text.DecimalFormat;



/**
 *
 * @author  bizzorg
 */
public class MortgageFrameCombo2 extends javax.swing.JFrame {

	/** Creates new form MortgageFrameCombo2 */
	public MortgageFrameCombo2() {
		initComponents();
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">						  
	private void initComponents() {

		principalLabel = new javax.swing.JLabel();
		termLabel = new javax.swing.JLabel();
		InterestLabel = new javax.swing.JLabel();
		mortgagePrincipalTextField = new javax.swing.JTextField();
		termComboBox = new javax.swing.JComboBox();
		interestComboBox = new javax.swing.JComboBox();
		jButton1 = new javax.swing.JButton();
		paymentValueField = new javax.swing.JTextField();
		paymentLabel = new javax.swing.JLabel();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		principalLabel.setText("Principal");

		termLabel.setText("Term");

		InterestLabel.setText("Interest");

		termComboBox.setEditable(true);
		termComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "360", "300", "240" }));

		interestComboBox.setEditable(true);
		interestComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "5.5", "5.75", "6" }));
		interestComboBox.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				interestComboBoxActionPerformed(evt);
			}
		});

		jButton1.setText("Calculate");
		jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				jButton1MouseClicked(evt);
			}
		});

		paymentLabel.setText("Payment");

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(
			layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addGroup(layout.createSequentialGroup()
						.addGap(51, 51, 51)
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
							.addComponent(termComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
							.addComponent(termLabel)
							.addComponent(principalLabel))
						.addGap(73, 73, 73)
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
							.addComponent(InterestLabel)
							.addComponent(interestComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
							.addComponent(mortgagePrincipalTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)))
					.addGroup(layout.createSequentialGroup()
						.addGap(143, 143, 143)
						.addComponent(jButton1)))
				.addContainerGap(69, Short.MAX_VALUE))
			.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
				.addContainerGap(90, Short.MAX_VALUE)
				.addComponent(paymentLabel)
				.addGap(62, 62, 62)
				.addComponent(paymentValueField, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
				.addGap(80, 80, 80))
		);
		layout.setVerticalGroup(
			layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addGap(28, 28, 28)
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(principalLabel)
					.addComponent(mortgagePrincipalTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
				.addGap(18, 18, 18)
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(termLabel)
					.addComponent(InterestLabel))
				.addGap(18, 18, 18)
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(termComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
					.addComponent(interestComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
				.addGap(64, 64, 64)
				.addComponent(jButton1)
				.addGap(18, 18, 18)
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(paymentLabel)
					.addComponent(paymentValueField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
				.addContainerGap(57, Short.MAX_VALUE))
		);

		pack();
	}// </editor-fold>						

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {									  
MortgageCalculator mc = new MortgageCalculator();
	String prin = mortgagePrincipalTextField.getText();
	String inter = "0.0";
	String ter = "0";
	ter = (String)termComboBox.getSelectedItem();
	inter = (String)interestComboBox.getSelectedItem();
	mc.setLoanValue(prin, inter, ter);
	double pay = mc.getInterestPayment() + mc.getPrincipalPayment();
	NumberFormat formatter = new DecimalFormat("$#,##0.00");
	String s = formatter.format(pay);
	paymentValueField.setText(s);
	MortgagePopUp p = new MortgagePopUp();
	Thread t = new Thread(p);
	t.start();

}									 

private void interestComboBoxActionPerformed(java.awt.event.ActionEvent evt) {												 
// TODO add your handling code here:
}												

	/**
	* @param args the command line arguments
	*/
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new MortgageFrameCombo2().setVisible(true);
			}
		});
	}
			
private void mortgagePrincipalTextFieldActionPerformed(java.awt.event.ActionEvent evt) {														   
// TODO add your handling code here:
	
}														  


	 


	// Variables declaration - do not modify					 
	private javax.swing.JLabel InterestLabel;
	private javax.swing.JComboBox interestComboBox;
	private javax.swing.JButton jButton1;
	private javax.swing.JTextField mortgagePrincipalTextField;
	private javax.swing.JLabel paymentLabel;
	private javax.swing.JTextField paymentValueField;
	private javax.swing.JLabel principalLabel;
	private javax.swing.JComboBox termComboBox;
	private javax.swing.JLabel termLabel;
	// End of variables declaration				   
}


Here's the pop up code...
/*
 * MortgagePopUp.java
 *
 * Created on July 29, 2008, 8:39 PM
 */



/**
 *
 * @author  bizzorg
 */
public class MortgagePopUp extends javax.swing.JFrame implements Runnable{

	/** Creates new form MortgagePopUp */
	public MortgagePopUp() {
		initComponents();
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">						  
	private void initComponents() {

		jScrollPane1 = new javax.swing.JScrollPane();
		popupTextArea = new javax.swing.JTextArea();
		popupButton = new javax.swing.JButton();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		popupTextArea.setColumns(20);
		popupTextArea.setRows(5);
		jScrollPane1.setViewportView(popupTextArea);

		popupButton.setText("Exit");
		popupButton.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				popupButtonMouseClicked(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(
			layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addGroup(layout.createSequentialGroup()
						.addGap(43, 43, 43)
						.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE))
					.addGroup(layout.createSequentialGroup()
						.addGap(150, 150, 150)
						.addComponent(popupButton)))
				.addContainerGap(68, Short.MAX_VALUE))
		);
		layout.setVerticalGroup(
			layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addGap(41, 41, 41)
				.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
				.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
				.addComponent(popupButton)
				.addGap(23, 23, 23))
		);

		pack();
	}// </editor-fold>						

private void popupButtonMouseClicked(java.awt.event.MouseEvent evt) {										 
// TODO add your handling code here:
	dispose();
}										

	/**
	* @param args the command line arguments
	*/
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new MortgagePopUp().setVisible(true);
			}
		});
	}

	// Variables declaration - do not modify					 
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JButton popupButton;
	private javax.swing.JTextArea popupTextArea;
	// End of variables declaration				   

	public void run() {
		setVisible(true);
	}

}


Is This A Good Question/Topic? 0
  • +

Replies To: How to I store and retrieve data for pop up windows in Java?

#2 lordms12  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 30
  • View blog
  • Posts: 339
  • Joined: 16-February 08

Re: How to I store and retrieve data for pop up windows in Java?

Posted 06 August 2008 - 12:19 PM

What do you mean?
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: How to I store and retrieve data for pop up windows in Java?

Posted 06 August 2008 - 06:13 PM

OK this is NOT a pop up window
A pop up window is somenthing from the JOptionPane class
Here you wrote (or your teacher wrote) his/your own class named MortgagePopUp

You have to have a method that will retreive the text (getText()) from the JTextField in that class
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1