Hello Dear Brothers and sisters
How are you................?
I'm Student of bscs in 6th semester
i write three programs but all of these are giving errors and i'm not able to findout probelm. but i thing problem is some where with CONTAINER
please check all these
Thanks
First One
import javax.swing.*;
public class FlowLayout{
JFrame myFrame;
JButton b1, b2, b3, b4, b5;
//method used for setting layout of GUI
public void initGUI(){
myFrame = new JFrame("Flow Layout");
Container c = myFrame.getContentPane();
c.setLayout(new FlowLayout());
b1 = new JButton("Next Button");
b2 = new JButton("Previous Button");
b3 = new JButton("Back Button");
b4 = new JButton("Last Button");
b5 = new JButton("Exit");
c.add(b1);
c.add(b2);
c.add(b3);
c.add(b4);
c.add(b5);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setSize(100, 150);
myFrame.setVisible(true);
}//end initGui method
public FlowLayoutTest(){//defualt constructor
initGUI();
}
public static void main (String[] args){
FlowLayoutTest TestOne = new FlowLayoutTest();
}
}
Second One
//import java.awt.*;
import javax.swing.*;
public class GUITest{
JFrame myFrame;
JTextField tf;
JButton b;
//method use for setting layout of GUI
public void initGUI(){
//step 2: setup the top level container
myFrame = new JFrame();
//Setup 3: Get the component area of the top-level container
Conntainer c = myFrame.getContentPane();
//Setup 4: Apply layout
c.setLayout(new FlowLayout());
//Setup 5: create & add components
JTextField tf = new JTextField(10);
JButton b1 = new JButton ("My Button");
c.add(tf);
c.add(b);
//Setup 6: set size of frame and make it visible
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setSize(200, 150);
myFrame.setVisible(true);
}
//end initGUI METHOD
public GUITest(){ //default constructor
initGUI();
}
public static void main (String args[]){
GUITest gui = new GUITest();
}
}
Third One
import java.awt.*;
import javax.swing.*;
public class GridLayoutTest{
JFrame myFrame;
JButton b1, b2, b3, b4, b5;
//method used for setting layout of GUI
public void initGUI(){
myFrame = new JFrame("Grid Layout");
Container c = myFrame.getContenPane();
c.setLayout(new GridLayout(3, 2));
b1 = new JButton ("Next Slide");
b2 = new JButton ("Previous Slide");
b3 = new JButton ("Back to Start");
b4 = new JButton ("Last Slide");
b5 = new JButton ("Exit");
c.add(b1);
c.add(b2);
c.add(b3);
c.add(b4);
c.add(b5);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setSize(300, 150);
myFrame.setVisible(true);
}
public GridLayoutTest(){
initGUI();
}
public static void mian (String args[]){
GridLayoutTest glTest = new GridLayoutTest();
}
}