Results 1 to 12 of 12
Thread: call JFrame 2 from JFrame1: help
- 04-06-2011, 04:34 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 8
- Rep Power
- 0
call JFrame 2 from JFrame1: help
hi all,
I created with Netbeans a project with two java files:
myproject
-myframe.java
-choose.java
each java files work fine on standalone. Moreover in myframe.java I created JFrame1 and in choose.java I created JFrame2
Now I need to launch JFrame2 from JFrame1(that is implemented in myframe.java).
my code is on button "START" present in JFrame1 is:
************
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
try {
String file = jTextField1.getText();
InputStream out = new FileInputStream(file);
Workbook book = WorkbookFactory.create(out);
String sheet=book.getSheetName(0);
JFrame w=new .choose();
w.setVisible(true);
.....
************
but in this way I see only JFrame2 without buttons and Jtextfield.
How can I do to solve my issue?
I tried to solve it with thread but I didn't find anything on how to launch a JFrame with thread.
Can someone help me please?
-
I'm not making much sense out of your question, and it may be hard to help you without code, but I'm afraid that a lot of your code will be auto-generated and thus very big and ugly. If you haven't done so, I suggest that you go through the Swing tutorials to learn how to create Swing GUI's by hand and without auto-generation since if you do this, you will understand Swing a lot better including using NetBeans to autogenerate your code.
Luck.
- 04-06-2011, 07:40 PM #3
Member
- Join Date
- Apr 2011
- Posts
- 8
- Rep Power
- 0
hi Fubarable,
thanks for your reply but believe me, I studied Java as you suggested but I decided to use Netbeans as it helps to create immediately JFrame.
I try to explain better with code and images:
JFrame1 is associated to file myframe.java as you can see from image:
[IMG]
[/IMG]
when I push butoom "CREA FILE" with follwing code:
where choose is the name of second file choose.java and this is the code:Java Code:private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { try { String file = jTextField1.getText(); InputStream out = new FileInputStream(file); Workbook book = WorkbookFactory.create(out); String sheet=book.getSheetName(0); JFrame w=new .choose(); w.setVisible(true);
and JFrame2 is associated to file choose.java:Java Code:public class choose extends javax.swing.JFrame { /** Creates new form choose */ public choose() { initComponents(); } ... public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new choose().setVisible(true); } }); }
[IMG]
[/IMG]
So my question is:
is it possible to launch JFrame2 when I click on buttom "CREA FILE"? or have I to create both JFrames in same file myframe.java?Last edited by dottbin; 04-06-2011 at 07:44 PM.
-
This may be a stupid question, but why do you even have a "JFrame2"/choose? Why not simply use one of the JOptionPanes to get a simple String input like this? And while I believe that you've done some studying, we all would benefit from further study, trust me. Also, you'll want to use the standard Java naming conventions when creating classes.
- 04-07-2011, 08:35 AM #5
Member
- Join Date
- Apr 2011
- Posts
- 8
- Rep Power
- 0
I learned from my collegues at work the respect for each one, so even if someone asks to me a possible stupid question, I never said to him that his question may be a 'stupid question'
You are right like I can use ajTextfield to solve it. But it is not my goal.
Anyway I'm interested to understand if it is possible in Java to open a second Frame form (like I've done in VB.net). It is not matter what JFrame2 does, the matter is how to launch second JFrame.
- 04-07-2011, 08:58 AM #6
The same way you 'launch' any JFrame. Construct it and setVisible(true)
db
- 04-07-2011, 09:12 AM #7
Member
- Join Date
- Apr 2011
- Posts
- 8
- Rep Power
- 0
thanks for replay.
I did as you said
but when I click on buttom, JFrame2 appears without buttom and JtextField as it should be (see by image posted). So I'm trying to understand how to launch this frame with its all components.Java Code:JFrame w=new .choose(); w.setVisible(true);
- 04-07-2011, 09:29 AM #8
To get better help sooner, post a SSCCE that clearly demonstrates your problem.
db
- 04-07-2011, 03:49 PM #9
Member
- Join Date
- Apr 2011
- Posts
- 8
- Rep Power
- 0
I'll do it in evening.
I posted as I understood what is problem.
When I click on buttom1 present on JFrame1 in order to launch also JFrame2 (as when I click on buttom1 also a txt file is created ) , JFrame2 is freezed so I cannot see it.
Meanwhile I want that JFrame1 is stopped, wait for value inserted in JFrame2 and then Jframe1 continues to create txt file.
I found some informations that I need to use concurrency (in particular event dispatch thread) and it is difficult.
My goal is in general to understand how I can launch a frame with a thread.
Is it possible?
- 04-07-2011, 06:37 PM #10
Use a modal JDialog or a static method of JOptionPane that shows one.I want that JFrame1 is stopped, wait for value inserted in JFrame2 and then Jframe1 continues to create txt file.
db
- 04-07-2011, 07:33 PM #11
Member
- Join Date
- Apr 2011
- Posts
- 8
- Rep Power
- 0
Sorry Darryl,
can I implement a list(multiselection) with several values with JDialog?
as you and Fubarable said with JOptionPane I can insert only a single value:
If your answer is yes, where can I find some example?Java Code:String inputvalue=JOptionPane.showInputDialog("Insert Source RNCid");Last edited by dottbin; 04-07-2011 at 08:43 PM.
- 04-07-2011, 11:16 PM #12
Similar Threads
-
call by value and call by reference in java
By sandeepsai39 in forum New To JavaReplies: 7Last Post: 08-12-2010, 11:03 AM -
to pass a parameter from a jframe children to its jframe mother
By anix in forum NetBeansReplies: 5Last Post: 06-14-2010, 06:10 PM -
Passing data from one JFrame to another JFrame
By tarami in forum New To JavaReplies: 3Last Post: 08-06-2009, 05:44 PM -
How to make a Jframe un-focusable when another Jframe is active?
By Robert_85 in forum Advanced JavaReplies: 4Last Post: 04-22-2009, 11:02 PM -
how to access jTextField of one JFrame1 from JFrame2 & Modify JTextField contents
By sumit1mca in forum AWT / SwingReplies: 1Last Post: 01-30-2009, 06:44 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks