Tuesday 1 July 2014

java GUI first program

Here are the two file to make the first program in java

in first file you can write


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package javagui;

/**
 *
 * @author jawadmahmood
 */
import java.awt.*;
import javax.swing.*;

public class JavaClassGui {
   
   JFrame  myFrame ;
   JTextField tf;
   JButton b1;
 
   
    public void initGui()
    {
       
        myFrame = new JFrame();
        Container c = myFrame.getContentPane();
        c.setLayout( new FlowLayout());
        tf = new JTextField(10);
        b1 = new JButton("My Button");
        c.add(tf);
        c.add(b1);
        myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        myFrame.setSize(500,350);
        myFrame.setVisible(true);
       
       
    }
   
    public JavaClassGui()
    {
        initGui();
    }
   
}


and the file images is 





and the main class file is 

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package javagui;

/**
 *
 * @author jawadmahmood
 */
public class JavaGui {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        
        JavaClassGui g = new JavaClassGui(); 
        
        
    }
    
}



and the image is 





then run the program and you will get the result 


as below 




1 comment: