Thursday 7 May 2015

FLOW LAYOUT PROGRAM IN JAVA

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

/**
<appletcode=flowlayout.class width=500 height=500>
</applet>
*/

public class flowlayout extends Applet implements ActionListener
{
Button b1,b2,b3,b4;
String result;

public void init()
{
b1=new Button(“one”);
b2=new Button(“two”);
b3=new Button(“three”);
b4=new Button(“four”);
setLayout(new FlowLayout(FlowLayput.LEFT,10,10));

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);

add(b1);
add(b2);
add(b3);
add(b4);
}

public void actionPerformed(ActionEvent e)
{
String str=e.getActionCommand();
if(str.equals(“one”))
{
result=”YOU CLICKED BUTTON ONE”;
repaint();
}
else if(str.equals(“two”))
{
result=”YOU CLICKED BUTTON TWO”;
repaint();
}
else if(str.equals(“three”))
{
result=”YOU CLICKED BUTTON THREE”;
repaint();
}
else
{
result=”YOU CLICKED BUTTON FOUR”;
repaint();
}
}

public void paint()
{
g.drawString(result,50,350);
}
}




No comments:

Post a Comment