package test;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Change extends JFrame implements ActionListener
{
private JButton button1,button2,button3;
Container c;
public Change()
{
super("Change");
button1 = new JButton("Left");
button2 = new JButton("Center");
button3 = new JButton("Right");
c =getContentPane();
c.setLayout(new FlowLayout(FlowLayout.LEFT));
c.add(button1);
c.add(button2);
c.add(button3);
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
setSize(400,400);
show();
}
public void actionPerformed(ActionEvent e)
{
String command = e.getActionCommand();
if (command.equals("Left"))
{ c.setLayout(new FlowLayout(FlowLayout.LEFT));
}
if (command.equals("Center"))
c.setLayout(new FlowLayout(FlowLayout.CENTER));
if (command.equals("Right"))
c.setLayout(new FlowLayout(FlowLayout.RIGHT));
}
public static void main(String args[])
{
Change cpp = new Change();
cpp.addWindowListener(new MyWindowListener()); }
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Change extends JFrame implements ActionListener
{
private JButton button1,button2,button3;
Container c;
public Change()
{
super("Change");
button1 = new JButton("Left");
button2 = new JButton("Center");
button3 = new JButton("Right");
c =getContentPane();
c.setLayout(new FlowLayout(FlowLayout.LEFT));
c.add(button1);
c.add(button2);
c.add(button3);
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
setSize(400,400);
show();
}
public void actionPerformed(ActionEvent e)
{
String command = e.getActionCommand();
if (command.equals("Left"))
{ c.setLayout(new FlowLayout(FlowLayout.LEFT));
}
if (command.equals("Center"))
c.setLayout(new FlowLayout(FlowLayout.CENTER));
if (command.equals("Right"))
c.setLayout(new FlowLayout(FlowLayout.RIGHT));
}
public static void main(String args[])
{
Change cpp = new Change();
cpp.addWindowListener(new MyWindowListener()); }
}
解决方案 »
- 如何把java编写的东西变成exe可执行文件?
- 如何用queue来实现stack?™
- 求Java打印bmp格式图片代码
- 请教default问题
- java怎样中利用对话框中取得的文件目录来创建目录
- 高手们,帮我看下改下APPLET,多谢
- 请问有没有工具可以将db中的table映射生成bean?
- 狂送100分,进入就送分,每月想赚3000者请进入,保证有赚$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
- 问个没有水平的问题?(回答了马上结贴给分)
- Thread问题!
- 奇怪!!!jdk5的doc里没有AbstractStringBuider这个类?谁能给各解释!!!
- gridwidth,weightx到底怎么使用?
{ c.setLayout(new FlowLayout(FlowLayout.LEFT));
//这里加个this.validate;看看
}
import java.awt.event.*;
import javax.swing.*;public class Change extends JFrame implements ActionListener {
private JButton button1, button2, button3; Container c; public Change() {
super("Change");
button1 = new JButton("Left");
button2 = new JButton("Center");
button3 = new JButton("Right");
c = getContentPane();
c.setLayout(new FlowLayout(FlowLayout.LEFT));
c.add(button1);
c.add(button2);
c.add(button3);
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
setSize(400, 400);
show();
} public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if (command.equals("Left")) {
c.setLayout(new FlowLayout(FlowLayout.LEFT));
}
if (command.equals("Center")) {
c.setLayout(new FlowLayout(FlowLayout.CENTER));
}
if (command.equals("Right")) {
c.setLayout(new FlowLayout(FlowLayout.RIGHT));
}
((JComponent) c).revalidate();
} public static void main(String args[]) {
Change cpp = new Change();
}
}