Results 1 to 13 of 13
- 03-18-2010, 07:15 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 28
- Rep Power
- 0
- 03-18-2010, 07:30 PM #2
What?! :confused:
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 03-18-2010, 07:33 PM #3
Member
- Join Date
- Nov 2009
- Posts
- 28
- Rep Power
- 0
Sorry if i was unclear!
I have two jFrames one is called MainMenu and the other is called About
i want to open the About jFrame from a button which is located in MainMenu?
- 03-18-2010, 07:45 PM #4
Ok, fine. About should be a JDialog as it it a 'child' of MianMenu. Where are you stuck? Getting the button to work? Opening About? What is your code? Compiler errors? Runtime exceptions?
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 03-18-2010, 08:00 PM #5
Member
- Join Date
- Nov 2009
- Posts
- 28
- Rep Power
- 0
i am trying to do this in the MainMenu form
and in the About.java file i have this as a main method...Java Code:private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { About.main();
So why wont it open?Java Code:public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new About().setVisible(true); }
- 03-18-2010, 08:53 PM #6
What?! You're calling a completely different method. You don't get any compiler errors or runtime exceptions?
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 03-18-2010, 08:59 PM #7
Member
- Join Date
- Nov 2009
- Posts
- 28
- Rep Power
- 0
yeah it wont compile....and i dont know what code to add around it that makes this button work
here is the MainMenu form
And here is the About FormJava Code:/* * MainMenu.java * * Created on March 18, 2010, 2:29 PM */ package javaapplication2; /** * * @author sachinparmar */ public class MainMenu extends javax.swing.JFrame { /** Creates new form MainMenu */ public MainMenu() { 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(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jPanel1.setBackground(new java.awt.Color(255, 255, 255)); jButton1.setText("Exit"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setText("About"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jButton4.setText("Donor"); jButton5.setText("Donation"); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); jLabel1.setBackground(new java.awt.Color(255, 255, 255)); jLabel1.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 70)); jLabel1.setForeground(new java.awt.Color(51, 153, 255)); jLabel1.setText("Unicef"); jLabel2.setBackground(new java.awt.Color(51, 153, 255)); jLabel2.setFont(new java.awt.Font("Microsoft Sans Serif", 2, 20)); jLabel2.setForeground(new java.awt.Color(51, 153, 255)); jLabel2.setText("A Day For Change"); org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup() .addContainerGap(308, Short.MAX_VALUE) .add(jLabel1) .add(20, 20, 20)) .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup() .addContainerGap(332, Short.MAX_VALUE) .add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 175, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addContainerGap()) .add(jPanel1Layout.createSequentialGroup() .add(195, 195, 195) .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) .add(org.jdesktop.layout.GroupLayout.LEADING, jButton4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.LEADING, jButton5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap(230, Short.MAX_VALUE)) .add(jPanel1Layout.createSequentialGroup() .add(jButton1) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(jButton2) .addContainerGap(370, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel1Layout.createSequentialGroup() .addContainerGap() .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 78, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jLabel2) .add(48, 48, 48) .add(jButton4) .add(18, 18, 18) .add(jButton5) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 29, Short.MAX_VALUE) .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jButton1) .add(jButton2)) .addContainerGap()) ); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) ); pack(); }// </editor-fold> private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { System.exit(0);// TODO add your handling code here: } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new MainMenu().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton4; private javax.swing.JButton jButton5; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JPanel jPanel1; // End of variables declaration }
Java Code:/* * NewJFrame.java * * Created on March 18, 2010, 2:05 PM */ package javaapplication2; /** * * @author sachinparmar */ public class About extends javax.swing.JFrame { /** Creates new form NewJFrame */ public About() { 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(); jPanel2 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jLabel10 = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jPanel2.setBackground(new java.awt.Color(255, 255, 255)); jLabel1.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 25)); // NOI18N jLabel1.setForeground(new java.awt.Color(51, 153, 255)); jLabel1.setText("Unicef Charity Admin System"); jLabel2.setText("Prodcut Version:"); jLabel3.setText("Name:"); jLabel4.setText("Created By:"); jLabel5.setText("1.0"); jLabel6.setText("Group B23"); jLabel7.setText("Sachin Parmar"); jLabel8.setText("Amar Tanna"); jLabel9.setText("Rosemond Safo"); jLabel10.setText("Katri Miles"); jLabel11.setText("Swing GUI I:"); jLabel12.setText("Created By Sachin Parmar"); org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel2Layout.createSequentialGroup() .add(11, 11, 11) .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jLabel1) .add(jPanel2Layout.createSequentialGroup() .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(jLabel4) .add(jLabel2) .add(jLabel11) .add(jLabel3)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jLabel12) .add(jLabel7) .add(jLabel6) .add(jLabel5) .add(jLabel8) .add(jLabel9) .add(jLabel10)))) .addContainerGap(51, Short.MAX_VALUE)) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel2Layout.createSequentialGroup() .addContainerGap() .add(jLabel1) .add(18, 18, 18) .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel2) .add(jLabel5)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel6) .add(jLabel3)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel7) .add(jLabel4)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jLabel8) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jLabel9) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jLabel10) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabel12) .add(jLabel11)) .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) ); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) ); 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 About().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; // End of variables declaration }
- 03-18-2010, 09:03 PM #8
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
-
You would need to create a New About object and set it's visible to true. But having said that, again, "about" shouldn't be a JFrame but rather a JDialog. Even better, have it produce a JPanel and then you can put it into a JDialog or JOptionPane.
If you really want to learn to do Swing coding, don't let NetBeans create your code for you as by doing this, you are missing out on how Swing works. Instead go to the Sun/Oracle Swing tutorials. Later as you get better with your Swing code, sure let NetBeans generate some code if you want something quick and dirty, but for now, all the code generation is going to do is to hamper your Swing education.
- 03-18-2010, 09:06 PM #10
Member
- Join Date
- Nov 2009
- Posts
- 28
- Rep Power
- 0
sorry for being vague...basically when i try to compile it says that there is no main method present in About, therefore it wont allow me to run my interface
- 03-18-2010, 09:09 PM #11
Oh, don't bother to provide the exact error messages. We can ask our crystal balls. Mine says that you probably have a mistake in your code.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
-
There's no main method with empty parameters in about, as the one you have takes String[], but still even if you could call About's main, it's not the way you should be doing this. Please see my replies above.
- 03-28-2010, 06:53 AM #13
Member
- Join Date
- Mar 2010
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Open JFrame
By AndersBjörnör in forum AWT / SwingReplies: 2Last Post: 12-01-2009, 09:03 PM -
Link between two JFrame using JButton
By Ravi Ranjan in forum NetBeansReplies: 2Last Post: 06-09-2009, 10:30 PM -
[SOLVED] How to close the current form when i open a new form?
By tpyq in forum NetBeansReplies: 6Last Post: 11-28-2008, 06:55 AM -
Open specific folder form JSP
By roseline43 in forum New To JavaReplies: 2Last Post: 09-02-2008, 07:53 PM -
how to click a jbutton and open an url
By katie in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 10:44 PM


LinkBack URL
About LinkBacks


Bookmarks