Results 1 to 5 of 5
- 02-03-2012, 09:02 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
Using JFrame interfaces
Hi,
I'm new to Java, and I'm trying to make a basic app.
I need to do the following.
I have SendMessage.java and View.java.
A button in View.java hides View.java, and now im trying to put a piece of code that shows a new JFrame i made called Confirm.java.
Here is what my files look like (not all code just the essential):
SendMessage.java
View.javaJava Code:public class SendMessage { /** * @param args the command line arguments */ public static void main(String[] args) { View showView = new View(); showView.setVisible(true); Confirm showConfirm = new Confirm(); showConfirm.setVisible(false); } }
Confirm.java doesn't have anything yet.Java Code:public class View extends javax.swing.JFrame { /** * Creates new form View */ public View() { initComponents(); } @SuppressWarnings("unchecked") private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { setVisible(false); // I guess I need to put something here! <--------------------------------------------- System.out.println(jTextField1.getText()); System.out.println(); System.out.println(jTextField2.getText()); System.out.println(); System.out.println(jTextArea2.getText()); }
I'm sure its an easy one.
Thanks for all your help!
AndreasLast edited by Andreas; 02-03-2012 at 09:50 PM.
-
Re: [EASY] Playing with JFrame interfaces
um,... what is your question exactly?
- 02-03-2012, 11:01 PM #3
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
Re: [EASY] Playing with JFrame interfaces
Crossposted: Using JFrame interfaces
- 02-03-2012, 11:35 PM #4
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
-
Re: [EASY] Playing with JFrame interfaces
If you need to have one object have access to another, then the first object needs a reference to the second. You have one of two options here:
- Create the Confirm object inside of View so the reference is readily available, or
- Pass a reference to the Confirm object into View from the main method by either passing the confirm object's reference into View's constructor or in a separate setConfirm(Confirm confirm) method.
Having said this, it's a very ugly program design to have windows popping into and out of view. Most will either show a dialog on top of a main window or swap views on a stable main window. For my money for a confirm dialog, I'd use a dialog such as a JOptionPane or a JDialog and keep the main window in view.
Also, please read the link that doWhile provides to you in your cross-post. It's not fair to us for you to cross-post without notifying us.
Similar Threads
-
Playing a WAV or MP3
By meesterpickles in forum New To JavaReplies: 7Last Post: 12-19-2011, 02:59 AM -
Playing . MP3 in JAVA
By UJJAL DHAR in forum Advanced JavaReplies: 1Last Post: 12-12-2011, 03:54 PM -
sound playing
By nikkka in forum Threads and SynchronizationReplies: 1Last Post: 04-10-2011, 05:38 PM -
Wav player not playing
By RightGoodEnt in forum CLDC and MIDPReplies: 0Last Post: 02-13-2011, 04:23 PM -
playing audio in J-App??
By ashton in forum New To JavaReplies: 3Last Post: 01-30-2009, 08:50 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks