编写一个窗口,在上面放一个标签JLabel和两个按钮JButton,设置面板布局为GridLayout。
1个回答
展开全部
package questions.baidu;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Q552516448482721972 {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable(){
@Override public void run(){
final JFrame frame = new JFrame("Hello");
final JLabel label = new JLabel("Good");
final ActionListener action = new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
label.setText(arg0.getActionCommand());
}
};
final JButton b1 = new JButton("哈哈");
final JButton b2 = new JButton("你好");
b1.addActionListener(action);
b2.addActionListener(action);
frame.add(label, BorderLayout.PAGE_START);
frame.add(b1, BorderLayout.LINE_START);
frame.add(b2, BorderLayout.LINE_END);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询