Results 1 to 3 of 3
- 09-19-2008, 02:05 PM #1
Member
- Join Date
- Jun 2008
- Posts
- 39
- Rep Power
- 0
Parent & Child window issues......
Hello friends,,,,
I am very new to java. Parent window is having on command button if i click that button i am doing some operation in action performed method...... The operations are ........ open a child window and next statement invoke a
simple function of child window in parent window........ the issue is when i invoke a child window method it will seconds to complete. meanwhile child window shows blank page it means Hang........ upto when the goes to end.....
pls help me how to solve this problem........ Sorry my poor english..... i have given the code.....
Parent.java
import java.awt.*;
public class Send extends javax.swing.JFrame {
Child d;
public Send() {
initComponents();
// d=new Child(new javax.swing.JFrame(),false);
}
private void initComponents() {//GEN-BEGIN:initComponents
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
jLabel1.setText("jLabel1");
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 60, -1, -1));
jLabel2.setText("jLabel2");
getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 60, -1, -1));
jButton1.setText("Open New Window");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 110, -1, -1));
pack();
}//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// Add your handling code here:
this.setVisible(false);
//System.out.println("Child form event :"+d.getComponents()Graphics());
d=new Child(new javax.swing.JFrame(),true,1000);
if(d.send()==false)
{
}
//d.dispose();
System.out.println("Child form event :"+d.getGraphics());
}//GEN-LAST:event_jButton1ActionPerformed
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
System.exit(0);
}//GEN-LAST:event_exitForm
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new Send().show();
}
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JButton jButton1;
}
child.java
import java.awt.*;
public class Child extends javax.swing.JDialog {
/** Creates new form Child */
Send d=new Send();
public Child(java.awt.Frame parent, boolean modal,int n) {
super(parent, modal);
m=n;
initComponents();
send();
this.show();
}
private void initComponents() {//GEN-BEGIN:initComponents
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
count = new javax.swing.JLabel();
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
jLabel1.setText("welcome ");
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 30, -1, -1));
jLabel2.setText("no");
getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 100, -1, -1));
count.setText(" ");
getContentPane().add(count, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 100, -1, -1));
pack();
}//GEN-END:initComponents
/** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
setVisible(false);
dispose();
}//GEN-LAST:event_closeDialog
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new Child(new javax.swing.JFrame(), true,0).show();
}
int m;
public boolean send()
{
// this.setCo
this.setVisible(true);
System.out.println("MVALUE :"+m);
try{
for (int i=0;i<=m;i++)
{
count.setText(String.valueOf(i));
System.out.println("MVALUE :"+i);
// Thread.sleep(1000);
}
d.show();
}catch(Exception e)
{
e.printStackTrace();
}
return false;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel count;
// End of variables declaration//GEN-END:variables
}
- 09-20-2008, 08:41 AM #2
Java Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; public class SendRx extends JFrame { public SendRx() { initComponents(); } private void initComponents() { jLabel1 = new JLabel(); jLabel2 = new JLabel(); jButton1 = new JButton(); getContentPane().setLayout(null); setDefaultCloseOperation(EXIT_ON_CLOSE); jLabel1.setText("jLabel1"); add(jLabel1, 50, 60); jLabel2.setText("jLabel2"); add(jLabel2, 130, 60); jButton1.setText("Open New Window"); jButton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jButton1ActionPerformed(evt); } }); add(jButton1, 40, 110); setSize(400,200); } private void add(JComponent c, int x, int y) { c.setSize(c.getPreferredSize()); c.setLocation(x, y); getContentPane().add(c); } private void jButton1ActionPerformed(ActionEvent evt) { // Add your handling code here: this.setVisible(false); //System.out.println("Child form event :"+d.getComponents()Graphics()); // d=new Child(this, true, 1000); // modal freezes everything! final Child d=new Child(this, false, 10); // Do this on a background thread so it will be safe // to [i]sleep[/i]. Sleeping on the edt (event dispatch // thread) causes everything to stop; not recommended. new Thread(new Runnable() { public void run() { if(d.send()) { dispose(); } else { setVisible(true); } d.dispose(); } }).start(); System.out.println("Child form event :"+d.getGraphics()); } public static void main(String[] args) { new SendRx().setVisible(true); } private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JButton jButton1; } class Child extends JDialog { SendRx d; int m; public Child(SendRx parent, boolean modal, int n) { super(parent, modal); d = parent; m=n; initComponents(); this.setVisible(true); } private void initComponents() { jLabel1 = new JLabel(); jLabel2 = new JLabel(); count = new JLabel(); getContentPane().setLayout(null); setDefaultCloseOperation(DISPOSE_ON_CLOSE); jLabel1.setText("welcome "); add(jLabel1, 130, 30); jLabel2.setText("no"); add(jLabel2, 60, 100); count.setText("need some space"); count.setBorder(BorderFactory.createEtchedBorder()); add(count, 140, 100); setSize(400, 200); } private void add(JComponent c, int x, int y) { c.setSize(c.getPreferredSize()); c.setLocation(x, y); getContentPane().add(c); } public static void main(String[] args) { new Child(new SendRx(), false, 0).setVisible(true); } public boolean send() { System.out.println("MVALUE :"+m); for (int i=0;i<=m;i++) { count.setText(String.valueOf(i)); System.out.println("MVALUE :"+i); try{ Thread.sleep(1000); } catch(Exception e) { e.printStackTrace(); return false; } } return true; } private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel count; }
- 09-20-2008, 09:21 AM #3
Member
- Join Date
- Jun 2008
- Posts
- 39
- Rep Power
- 0
Similar Threads
-
how to get the child class in inheritance?
By java_fun2007 in forum New To JavaReplies: 7Last Post: 09-29-2010, 09:35 AM -
Child Labor
By freddieMaize in forum Forum LobbyReplies: 1Last Post: 11-16-2008, 08:59 PM -
passing a value from parent thread to child thread
By sachinj13 in forum Threads and SynchronizationReplies: 7Last Post: 09-07-2008, 09:06 PM -
disable parent window
By ismailsaleh in forum AWT / SwingReplies: 1Last Post: 01-07-2008, 11:15 PM -
How to create a new pop up window from jsp without changing the URL address of parent
By nihar1213 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 08-03-2007, 04:21 PM


LinkBack URL
About LinkBacks

Bookmarks