Results 1 to 9 of 9
- 06-01-2009, 07:34 AM #1
Member
- Join Date
- Feb 2009
- Posts
- 50
- Rep Power
- 0
- 06-01-2009, 07:58 AM #2
Hi Santosh,
How you are calling the new Frame? Please send me the code so that I can give suggestions.
-Regards
RamyaRamya:cool:
- 06-01-2009, 10:59 AM #3
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
Just create a method and use something like: frame2.setTextFieldText("Hello World");
I die a little on the inside...
Every time I get shot.
-
Best not to say this as nobody likes to be put under pressure, least of all volunteers.
This is not a code mill. Much better is to show what you've tried and perhaps we can help you find your way.can anybody send me a code. i have tried but i didnt get any solution.
- 06-02-2009, 07:31 AM #5
Hi,
I have written a piece of code as a sample.As Fubarable said,you should put ur code and ask the doubt.You shouldn't expect a complete code as u can't learn.
-Regards
Ramya
Java Code:import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.HashMap; import javax.swing.JButton; import javax.swing.JTextField; import javax.swing.JFrame; public class FrameCommunication{ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { //ChildWindow creation DetailView detail= new DetailView(); //ParentWindow creation by passing the child object MainView main = new MainView(detail); main.setVisible(true); detail.setVisible(true); } }); } } class MainView extends JFrame implements ActionListener{ JTextField textField; DetailView detailObj; public MainView(DetailView detailObj) { this.detailObj = detailObj; setTitle("Main"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().setLayout(new BorderLayout()); JButton button = new JButton("Transfer Content"); textField = new JTextField(); button.addActionListener(this); getContentPane().add(textField, BorderLayout.CENTER); getContentPane().add(button, BorderLayout.SOUTH); pack(); setSize(200,200); }//mainView constructor //Whenever the button is pressed the textvalue will be tranfered from this parent window //and set as a text to child indows textfield. public void actionPerformed(ActionEvent e) { detailObj.textField.setText(textField.getText()); } }//Main View class class DetailView extends JFrame { JTextField textField; public DetailView(){ setTitle("Detail"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().setLayout(new BorderLayout()); textField = new JTextField(); getContentPane().add(textField, BorderLayout.SOUTH); pack(); setSize(200,200); }//cons } //DetailView classLast edited by RamyaSivakanth; 06-02-2009 at 07:36 AM.
Ramya:cool:
- 06-03-2009, 11:47 AM #6
Member
- Join Date
- Feb 2009
- Posts
- 50
- Rep Power
- 0
how can i access on frame window to another window
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* frametest.java
*
* Created on Jun 1, 2009, 9:32:50 AM
*/
/**
*
* @author Santhosh
*/
public class frametest extends javax.swing.JFrame {
String frameval="";
/** Creates new form frametest */
public frametest() {
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() {
jFrame1 = new javax.swing.JFrame();
jFileChooser1 = new javax.swing.JFileChooser();
jPanel1 = new javax.swing.JPanel();
frametext = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
sendbutton = new javax.swing.JButton();
javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
jFrame1.getContentPane().setLayout(jFrame1Layout);
jFrame1Layout.setHorizontalGroup(
jFrame1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
jFrame1Layout.setVerticalGroup(
jFrame1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.create TitledBorder(null, "Frametest", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICAT ION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 3, 14), new java.awt.Color(255, 51, 51))); // NOI18N
jLabel2.setText("enter value:");
sendbutton.setText("send");
sendbutton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sendbuttonActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(44, 44, 44)
.addComponent(frametext, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addComponent(sendbutton)
.addContainerGap(33, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(frametext, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(sendbutton))
.addComponent(jLabel1))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_S IZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGap(0, 351, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_S IZE, Short.MAX_VALUE)))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGap(0, 99, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_S IZE, Short.MAX_VALUE)))
);
pack();
}// </editor-fold>
private void sendbuttonActionPerformed(java.awt.event.ActionEve nt evt) {
// TODO add your handling code here:
// java.awt.EventQueue.invokeLater(new Runnable()
// {
// public void run() {
/// new frametest().setVisible(true);
int val=0;
String val1="";
val1=frametext.getText();
System.out.println("val1" + ":" + val1);
val=Integer.parseInt(val1);
// }
// });
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run() {
new frametest().setVisible(true);
new frametest1().setVisible(true);
}
});
}
// Variables declaration - do not modify
public javax.swing.JTextField frametext;
private javax.swing.JFileChooser jFileChooser1;
private javax.swing.JFrame jFrame1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JButton sendbutton;
// End of variables declaration
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* frametest1.java
*
* Created on Jun 1, 2009, 11:04:48 AM
*/
/**
*
* @author Santhosh
*/
public class frametest1 extends javax.swing.JFrame {
/** Creates new form frametest1 */
public frametest1() {
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() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
frame1text = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.create TitledBorder(null, "frametest1", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICAT ION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(255, 102, 51))); // NOI18N
jLabel1.setText("value:");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(48, 48, 48)
.addComponent(jLabel1)
.addGap(48, 48, 48)
.addComponent(frame1text, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(139, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(24, 24, 24)
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(frame1text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(39, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap()))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGap(0, 137, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(13, Short.MAX_VALUE)))
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new frametest1().setVisible(true);
}
});
}
// Variables declaration - do not modify
public javax.swing.JTextField frame1text;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
// End of variables declaration
}
dear sir,
here i have created two frame windows in swing in netbeans 6.5
first frame window is frametest.java
second frame window is frametest1.java
in the frametest.java ,i have created button called send,when i click the button the data in textfield in first frame window is transferred to second frame window' s textfield. there is any bug in the code.
please give me any solution.
- 06-03-2009, 02:13 PM #7
Hi Santosh,
Have you gone thru my code?
Get the logic and try to incorporate in your code.Ramya:cool:
- 06-10-2009, 06:36 AM #8
Member
- Join Date
- Feb 2009
- Posts
- 50
- Rep Power
- 0
Regarding issue in form window
dear sir,
i am using netbeans 6.5,created simple swing GUI application ie form
frame1.java in that it has textfield and label enter any number and button called transfer.when right click the form,going to add from palette,it has features like swing containers,swing controls,swing menus,swing windows,AWT,Bean,java persistence.i am using swing windows i has features like frame ,dialog,filechooser,when i click frame does not appear.what is the problem.can give me solution.in that i want to create another textfield .when i click the button transfer in framr2.java the value in the textfield in frame1.java should appear in newly created textfleld this is my logic.my problem is when click the frame it does not appear.give me any solution.
thanks
santhosh babu
-
Recommendation 1: to learn Swing, don't use NetBeans to generate your application. Doing this will set your Swing education back several months.
Here is an example where a JFrame holds a JTextField and the text in the JTextField can be sent to JTextFields held in two JDialogs. In the first JDialog, the dialog and frame's JTextFields share the same model, and so the text is sent instantaneously. In the second JDialog, the text is sent from the JFrame to the JDialog only when the frame's "send" button has been pressed:
Java Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.text.Document; public class ShareFieldData { private static void createAndShowUI() { // create the jframe, and two JDialog's panels. final MainFramePanel mainFramePanel = new MainFramePanel(); final DialogPanel sendTextDialogPanel = new DialogPanel(); final DialogPanel shareDocDialogPanel = new DialogPanel(); // have the JTextField in the shareDocDialogPanel share model with // the mainFramePanel's JTextField shareDocDialogPanel.setDocument(mainFramePanel.getDocument()); // give the mainFramePanel's send button an ActionListener // that sends its JTextField's text to the // sendTextDialogPanel's JTextField mainFramePanel.addSendActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sendTextDialogPanel.setText(mainFramePanel.getText()); } }); // Create the JFrame and add our JPanel into it. JFrame frame = new JFrame("Main Frame"); frame.getContentPane().add(mainFramePanel.getMainPanel()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); // create the 2 JDialogs and add the jpanels into them JDialog shareDocDialog = new JDialog(frame, "Share Doc Dialog", false); shareDocDialog.getContentPane().add(shareDocDialogPanel.getMainPanel()); shareDocDialog.pack(); JDialog sendTextDialog = new JDialog(frame, "Send Text Dialog", false); sendTextDialog.getContentPane().add(sendTextDialogPanel.getMainPanel()); sendTextDialog.pack(); // position our dialogs and frame. int frameX = frame.getLocation().x; int frameY = frame.getLocation().y; int frameW = frame.getPreferredSize().width; int dialogW = sendTextDialog.getPreferredSize().width; int delta = 150; shareDocDialog.setLocation(frameX - delta, frameY - delta); sendTextDialog.setLocation(frameX + frameW + delta - dialogW, frameY - delta); // set them all visible, the jframe last so it has focus shareDocDialog.setVisible(true); sendTextDialog.setVisible(true); frame.setVisible(true); } public static void main(String[] args) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { createAndShowUI(); } }); } } /** * Creates JPanel that is placed in the main * JFrame. * @author Pete */ class MainFramePanel { private JPanel mainPanel = new JPanel(); private JTextField textField = new JTextField(12); private JButton sendBtn = new JButton("Send"); public MainFramePanel() { mainPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 15)); mainPanel.add(new JLabel("Enter Value: ")); mainPanel.add(Box.createHorizontalStrut(10)); mainPanel.add(textField); mainPanel.add(sendBtn); } /** * * @return text String contained in JTextField */ public String getText() { return textField.getText(); } /** * @param ActionListener added to the send JButton */ public void addSendActionListener(ActionListener al) { sendBtn.addActionListener(al); } public Document getDocument() { return textField.getDocument(); } public JComponent getMainPanel() { return mainPanel; } } /** * creates a JPanel that is placed inside of a JDialog * can set the panel's JTextField's document (model) so that * two JTextFields can share the same model (and thus the same text) * or can send text to this panel's JTextField * @author Pete */ class DialogPanel { private JPanel mainPanel = new JPanel(); private JTextField textField = new JTextField(12); public DialogPanel() { textField.setEditable(false); mainPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 15)); mainPanel.add(new JLabel("Value: ")); mainPanel.add(Box.createHorizontalStrut(10)); mainPanel.add(textField); } public JComponent getMainPanel() { return mainPanel; } public void setText(String text) { textField.setText(text); } /** * Let this panel's JTextField share the model (Document) * of another JTextField * @param Document */ public void setDocument(Document document) { textField.setDocument(document); } }
Similar Threads
-
Regarding issue in frame window
By santhosh_el in forum AWT / SwingReplies: 1Last Post: 06-01-2009, 08:10 AM -
i want to display decimal values in frame window
By santhosh_el in forum AWT / SwingReplies: 4Last Post: 03-16-2009, 09:07 AM -
How to move a ball across the applet window?
By getkiran in forum Java AppletsReplies: 3Last Post: 03-05-2009, 08:45 AM -
Read/Write of components of frame window
By Harish kumara M in forum AWT / SwingReplies: 0Last Post: 09-17-2008, 08:14 AM -
File drop zones don't move with window in Firefox
By jazgold in forum Java AppletsReplies: 2Last Post: 01-02-2008, 10:25 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks