展开全部
这样行吗?不行发邮件说详细点,370387501@qq.com
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Btn extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
public static void main(String args[]) {
Btn btn = new Btn();
btn.setVisible(true);
}
public Btn() {
super("Test");
getContentPane().setLayout(null);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
setBounds((d.width - 280) / 2, (d.height - 150) / 2, 280, 150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setBounds(16, 13, 246, 150);
getContentPane().add(panel);
final JLabel lable = new JLabel();
lable.setBounds(80, 50, 100, 30);
panel.add(lable);
JButton button1 = new JButton();
button1.setBounds(10, 10, 99, 28);
button1.setText(" 确定 ");
// 添加按钮监听事件
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 点击“确定”按钮后执行操作
lable.setText("按钮一被点击");
}
});
button1.setBorder(BorderFactory.createRaisedBevelBorder());
panel.add(button1);
JButton button2 = new JButton();
button2.setBounds(137, 10, 99, 28);
button2.setText(" 取消 ");
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 点击“取消”按钮后执行操作
lable.setText("按钮二被点击");
}
});
button2.setBorder(BorderFactory.createRaisedBevelBorder());
panel.add(button2);
}
}
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Btn extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
public static void main(String args[]) {
Btn btn = new Btn();
btn.setVisible(true);
}
public Btn() {
super("Test");
getContentPane().setLayout(null);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
setBounds((d.width - 280) / 2, (d.height - 150) / 2, 280, 150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setBounds(16, 13, 246, 150);
getContentPane().add(panel);
final JLabel lable = new JLabel();
lable.setBounds(80, 50, 100, 30);
panel.add(lable);
JButton button1 = new JButton();
button1.setBounds(10, 10, 99, 28);
button1.setText(" 确定 ");
// 添加按钮监听事件
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 点击“确定”按钮后执行操作
lable.setText("按钮一被点击");
}
});
button1.setBorder(BorderFactory.createRaisedBevelBorder());
panel.add(button1);
JButton button2 = new JButton();
button2.setBounds(137, 10, 99, 28);
button2.setText(" 取消 ");
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// 点击“取消”按钮后执行操作
lable.setText("按钮二被点击");
}
});
button2.setBorder(BorderFactory.createRaisedBevelBorder());
panel.add(button2);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询