Home > Java > Java – How to Ant Gui?

Java – How to Ant Gui?

Just a small but a very handy.
##############################################
1. GUI – will eat time – we used seperate GUI builder jvider.com
2. Action collect centrally
3. Programming
##############################################

Main.java
=========

// Simple Ant procedure
package directant;
/**
*
* @author shamun
*/
public class Main {
/**
* @param One main execute
*/
public static void main(String[] args) {
// Other tasks can be done here.
// Calling GUI
Gui gui = new Gui();
gui.setVisible(true);
}
}

// Simple Ant procedurepackage directant;
/** * * @author shamun */public class Main {
/**     * @param One main execute     */    public static void main(String[] args) {        // Other tasks can be done here.                // Calling GUI        Gui gui = new Gui();        gui.setVisible(true);    }
}

Gui.java
=======
package directant;

import javax.swing.JPanel;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.UIManager;

import javax.swing.UnsupportedLookAndFeelException;

import java.awt.*;

import java.awt.event.*;

/**

*

* @author shamun

*/

public class Gui extends JFrame implements ActionListener{

static Gui theGui;

JPanel pnPanel0;

JButton btBut0;

JButton btBut1;

public static void main( String args[] ) throws UnsupportedLookAndFeelException{

try

{

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

}

catch ( ClassNotFoundException e )

{

}

catch ( InstantiationException e )

{

}

catch ( IllegalAccessException e )

{

}

catch ( UnsupportedLookAndFeelException e )

{

}

theGui = new Gui();

}

public Gui(){

super( “TITLE” );

pnPanel0 = new JPanel();

GridBagLayout gbPanel0 = new GridBagLayout();

GridBagConstraints gbcPanel0 = new GridBagConstraints();

pnPanel0.setLayout( gbPanel0 );

btBut0 = new JButton( “shamun”  );

gbcPanel0.gridx = 1;

gbcPanel0.gridy = 2;

gbcPanel0.gridwidth = 15;

gbcPanel0.gridheight = 4;

gbcPanel0.fill = GridBagConstraints.BOTH;

gbcPanel0.weightx = 1;

gbcPanel0.weighty = 0;

gbcPanel0.anchor = GridBagConstraints.NORTH;

gbPanel0.setConstraints( btBut0, gbcPanel0 );

pnPanel0.add( btBut0 );

btBut1 = new JButton( “foo”  );

gbcPanel0.gridx = 7;

gbcPanel0.gridy = 11;

gbcPanel0.gridwidth = 11;

gbcPanel0.gridheight = 4;

gbcPanel0.fill = GridBagConstraints.BOTH;

gbcPanel0.weightx = 1;

gbcPanel0.weighty = 0;

gbcPanel0.anchor = GridBagConstraints.NORTH;

gbPanel0.setConstraints( btBut1, gbcPanel0 );

pnPanel0.add( btBut1 );

setDefaultCloseOperation( EXIT_ON_CLOSE );

setContentPane( pnPanel0 );

pack();

setVisible( true );

// Mannually created – Attach button actions

btBut1.addActionListener(this);

btBut1.addActionListener(new EventCentral());

}

// Mannually created

public void actionPerformed(ActionEvent e) {

//throw new UnsupportedOperationException(“Not supported yet.”);

System.out.print(“First thread \r\n”);

}

}// End of GUi

EventCentral.java
===============

// namespace

package directant;

// includes

import java.awt.event.*;

// Event Actions are listening on here.

public class EventCentral implements ActionListener {

// Not in use, we can use it as __construct.

public EventCentral(){}

// This is getting trigger by Gui.Java

public void actionPerformed(ActionEvent e) {

System.out.print(“Second thread \r\n”);

}

}

Advertisements
Categories: Java Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: