5 Replies - 4230 Views - Last Post: 21 June 2010 - 09:16 PM Rate Topic: -----

#1 blues90  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 20
  • Joined: 25-June 09

How can I make Button that can run another Java file?

Posted 21 June 2010 - 08:32 PM

Guys, i created a page names 'LoginForm.java' and want a button, when i clicked it, it will run my another java files names 'DesktopApplication1View.java'..how can i done this?

package desktopapplication1;

import java.io.*;

public class LoginForm extends javax.swing.JFrame {
BufferedReader in;

    public LoginForm() {
        initComponents();

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        button1 = new java.awt.Button();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(desktopapplication1.DesktopApplication1.class).getContext().getResourceMap(LoginForm.class);
        button1.setLabel(resourceMap.getString("button1.label")); // NOI18N
        button1.setName("button1"); // NOI18N
        button1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(190, Short.MAX_VALUE)
                .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(153, 153, 153))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(180, Short.MAX_VALUE)
                .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(96, 96, 96))
        );

        pack();
    }// </editor-fold>

    private void button1ActionPerformed(java.awt.event.ActionEvent evt) {

        // How can i write code to run a page names 'DesktopApplication1View.java' in same package?
        // Please show me here..pls.
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new LoginForm().setVisible(true);
            }
        });
    }

    private java.awt.Button button1;

}



Is This A Good Question/Topic? -3
  • +

Replies To: How can I make Button that can run another Java file?

#2 blues90  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 20
  • Joined: 25-June 09

Re: How can I make Button that can run another Java file?

Posted 21 June 2010 - 08:34 PM

Guys, i created a page names 'LoginForm.java' and want a button, when i clicked it, it will run my another java files names 'DesktopApplication1View.java'..how can i done this?

package desktopapplication1;

import java.io.*;

public class LoginForm extends javax.swing.JFrame {
BufferedReader in;

    public LoginForm() {
        initComponents();

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        button1 = new java.awt.Button();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(desktopapplication1.DesktopApplication1.class).getContext().getResourceMap(LoginForm.class);
        button1.setLabel(resourceMap.getString("button1.label")); // NOI18N
        button1.setName("button1"); // NOI18N
        button1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(190, Short.MAX_VALUE)
                .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(153, 153, 153))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(180, Short.MAX_VALUE)
                .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(96, 96, 96))
        );

        pack();
    }// </editor-fold>

    private void button1ActionPerformed(java.awt.event.ActionEvent evt) {

        // How can i write code to run a page names 'DesktopApplication1View.java' in same package?
        // Please show me here..pls.
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new LoginForm().setVisible(true);
            }
        });
    }

    private java.awt.Button button1;

}


Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8030
  • View blog
  • Posts: 31,176
  • Joined: 06-March 08

Re: How can I make Button that can run another Java file?

Posted 21 June 2010 - 08:40 PM

Asked to many times, I decided to write a CodeSnippet about it

http://www.dreaminco...snippet4460.htm

You should have search the forum first
Was This Post Helpful? 0
  • +
  • -

#4 Travis1012  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 36
  • View blog
  • Posts: 218
  • Joined: 05-August 09

Re: How can I make Button that can run another Java file?

Posted 21 June 2010 - 08:41 PM

I think you accidently submitted it twice. This is a duplicate thread of this thread.

EDIT: It seems the duplicate thread has been removed. Thank you.

EDIT: Thank you pbl for merging the topics.

This post has been edited by Travis1012: 21 June 2010 - 08:46 PM

Was This Post Helpful? 1
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8030
  • View blog
  • Posts: 31,176
  • Joined: 06-March 08

Re: How can I make Button that can run another Java file?

Posted 21 June 2010 - 08:44 PM

Second times you double post today

Topics merged
Was This Post Helpful? 2
  • +
  • -

#6 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 9041
  • View blog
  • Posts: 33,540
  • Joined: 27-December 08

Re: How can I make Button that can run another Java file?

Posted 21 June 2010 - 09:16 PM

NetBeans GUI Generator (and Java GUI Generators in general) produce cumbersome, excessive, and unmaintainable code. As Swing is so easy to use, you should really be writing your GUIs by hand. In fact, the Java Tutorials Section has quite a few Swing GUI tutorials, if you want to check them out.

As Java is an Object-Oriented language, (hint) your problem can be solved by creating Objects. You may also want to look into the JFrame setVisible() and dispose() methods.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1