netbeans中如何通过按钮跳转页面
展开全部
//写了一个简陋的代码,但是还基本能说明,代码如下:
package Qq;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class test extends JFrame implements ActionListener {
JButton jb1, jb2;
public test() {
jb1 = new JButton("测试1");
//这里设置监听
jb1.addActionListener(this);
//设别标记
jb1.setActionCommand("jb1");
//同上
jb2 = new JButton("测试2");
//同上
jb2.addActionListener(this);
jb2.setActionCommand("jb2");
this.setLayout(new GridLayout(1, 2));
this.add(jb1);
this.add(jb2);
this.setSize(500, 500);
this.setLocation(200, 200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
test t = new test();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getActionCommand().equals("jb1")) {
//这里添加你需要跳转的页面
System.out.println("我爱java1!");
}else if(e.getActionCommand().equals("jb2")){
//同上
System.out.println("我爱java2!");
}
}
}
package Qq;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class test extends JFrame implements ActionListener {
JButton jb1, jb2;
public test() {
jb1 = new JButton("测试1");
//这里设置监听
jb1.addActionListener(this);
//设别标记
jb1.setActionCommand("jb1");
//同上
jb2 = new JButton("测试2");
//同上
jb2.addActionListener(this);
jb2.setActionCommand("jb2");
this.setLayout(new GridLayout(1, 2));
this.add(jb1);
this.add(jb2);
this.setSize(500, 500);
this.setLocation(200, 200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
test t = new test();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getActionCommand().equals("jb1")) {
//这里添加你需要跳转的页面
System.out.println("我爱java1!");
}else if(e.getActionCommand().equals("jb2")){
//同上
System.out.println("我爱java2!");
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询