java 点允许没有反应 程序有main_我的java程序点击相应的button键没有反应?我想要实现的功能是点击“左齐”键,按钮左对齐,依此类推;...
我的源程序如下:importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassfirstextendsJFrameimplementsActionListener{Containerc;JButtonle=newJButton("左齊");...
我的源程序如下:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class first extends JFrame implements ActionListener
{
Container c;
JButton le=new JButton("左齊");
JButton mi=new JButton("居中");
JButton ri=new JButton("右齊");
FlowLayout fl=new FlowLayout();
public first()
{
super("流水版面配置");
c=getContentPane();
c.setLayout(fl);
c.add(le);
c.add(mi);
c.add(ri);
le.addActionListener(this);
mi.addActionListener(this);
ri.addActionListener(this);
setSize(400,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String s=e.getActionCommand();
if(s.equals("左齊"))
{
fl.setAlignment(FlowLayout.LEFT);
//this.invalidate();
//c.setLayout(fl);
System.out.println(s);
}
else
if(s.equals("居中"))
{
fl.setAlignment(FlowLayout.CENTER);
//this.invalidate();
//c.setLayout(fl);
System.out.println(s);
}
else
{
fl.setAlignment(FlowLayout.RIGHT);
//this.invalidate();
//c.setLayout(fl);
System.out.println(s);
}
}
public static void main(String[] args)
{
first f=new first();
f.addWindowListener(new MyWindowListener());
}
}
其中用到的MyWindowListener這個類的內(nèi)容如下:
import java.awt.event.*;
public class MyWindowListener implements WindowListener
{
public void windowActivated(WindowEvent e)
{
System.out.println("窗口為活動狀態(tài)");
}
public void windowClosed(WindowEvent e)
{
System.out.println("窗口為關(guān)閉狀態(tài)");
System.exit(0);
}
public void windowClosing(WindowEvent e)
{
System.out.println("窗口正在關(guān)閉");
System.exit(0);
}
public void windowDeactivated(WindowEvent e)
{
System.out.println("窗口不再活動");
}
public void windowDeiconified(WindowEvent e)
{
System.out.println("窗口由最小化變?yōu)檎?#34;);
}
public void windowIconified(WindowEvent e)
{
System.out.println("窗口為最小化");
}
public void windowOpened(WindowEvent e)
{
System.out.println("窗口首次可見");
}
}
展開
總結(jié)
以上是生活随笔為你收集整理的java 点允许没有反应 程序有main_我的java程序点击相应的button键没有反应?我想要实现的功能是点击“左齐”键,按钮左对齐,依此类推;...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vant 做表格_Vant List 列
- 下一篇: 手机版ziperello_Ziperel