添加按鈕監(jiān)聽。回見內(nèi)容寫成方法,然后調(diào)用即可。大概像下面這樣
超過十載行業(yè)經(jīng)驗,技術(shù)領(lǐng)先,服務至上的經(jīng)營模式,全靠網(wǎng)絡和口碑獲得客戶,為自己降低成本,也就是為客戶降低成本。到目前業(yè)務范圍包括了:網(wǎng)站設(shè)計、網(wǎng)站制作,成都網(wǎng)站推廣,成都網(wǎng)站優(yōu)化,整體網(wǎng)絡托管,微信小程序開發(fā),微信開發(fā),成都app開發(fā),同時也可以讓客戶的網(wǎng)站和網(wǎng)絡營銷和我們一樣獲得訂單和生意!
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?javax.swing.JButton;
public?class?Test?{
public?static?void?main(String?[]?args){
JButton?A?=?new?JButton("A");
JButton?B?=?new?JButton("B");
JButton?C?=?new?JButton("C");
A.addActionListener(new?ActionListener()?{
@Override
public?void?actionPerformed(ActionEvent?e)?{
methodA();
}
});
B.addActionListener(new?ActionListener()?{
@Override
public?void?actionPerformed(ActionEvent?e)?{
methodB();
}
});
C.addActionListener(new?ActionListener()?{
@Override
public?void?actionPerformed(ActionEvent?e)?{
methodA();
methodB();
}
});
}
public?static?void?methodA(){
//執(zhí)行A方法
}
public?static?void?methodB(){
//執(zhí)行B方法
}
}
加入在frame中的按鈕名為sure
Button sure=new Button("確定");
sure.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
frame1.setVisible(false);
Frame frame2=new Frame();
frame2.setVisible(true);
}
});
很簡單嘛,代碼如下
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Test {
static JFrame jf1 = new JFrame("jf1");
static JFrame jf2 = new JFrame("jf2");
static JButton jb = new JButton("click");
public static void main(String[] args) {
jf1.add(jb);
jf1.setSize(200, 200);
jf2.setSize(200, 200);
jf1.setVisible(true);
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
jf2.setVisible(true);
}
});
}
}