Bản quyền thuộc về TITV.vn,
vui lòng không đăng tải lại nội dung từ trang này.
Video giải thích chi tiết
https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
Code chi tiết
package view;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.nio.ByteOrder;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
public class MyCalculator extends JFrame {
public MyCalculator() {
this.setTitle("My Calculator");
this.setSize(300, 300);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JTextField jTextField = new JTextField(50);
JPanel jPanel_head = new JPanel();
jPanel_head.setLayout(new BorderLayout());
jPanel_head.add(jTextField, BorderLayout.CENTER);
JButton jButton_0 = new JButton("0");
JButton jButton_1 = new JButton("1");
JButton jButton_2 = new JButton("2");
JButton jButton_3 = new JButton("3");
JButton jButton_4 = new JButton("4");
JButton jButton_5 = new JButton("5");
JButton jButton_6 = new JButton("6");
JButton jButton_7 = new JButton("7");
JButton jButton_8 = new JButton("8");
JButton jButton_9 = new JButton("9");
JButton jButton_cong = new JButton("+");
JButton jButton_tru = new JButton("-");
JButton jButton_nhan = new JButton("*");
JButton jButton_chia = new JButton("/");
JButton jButton_bang = new JButton("=");
JPanel jPanel_buttons = new JPanel();
jPanel_buttons.setLayout(new GridLayout(5, 3));
jPanel_buttons.add(jButton_0);
jPanel_buttons.add(jButton_1);
jPanel_buttons.add(jButton_2);
jPanel_buttons.add(jButton_3);
jPanel_buttons.add(jButton_4);
jPanel_buttons.add(jButton_5);
jPanel_buttons.add(jButton_6);
jPanel_buttons.add(jButton_7);
jPanel_buttons.add(jButton_8);
jPanel_buttons.add(jButton_9);
jPanel_buttons.add(jButton_cong);
jPanel_buttons.add(jButton_tru);
jPanel_buttons.add(jButton_nhan);
jPanel_buttons.add(jButton_chia);
jPanel_buttons.add(jButton_bang);
this.setLayout(new BorderLayout());
this.add(jPanel_head, BorderLayout.NORTH);
this.add(jPanel_buttons, BorderLayout.CENTER);
this.setVisible(true);
}
public static void main(String[] args) {
try {
// com.sun.java.swing.plaf.gtk.GTKLookAndFeel
// com.sun.java.swing.plaf.motif.MotifLookAndFeel
// com.sun.java.swing.plaf.windows.WindowsLookAndFeel
// UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
// UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
// UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
new MyCalculator();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Đặng Trung Hiếu
Trả lờiXóasinh vien dang hoc
Trả lờiXóaĐã học và làm theo từ bài 1 đến bài 80.. bizz bizz!
Trả lờiXóahihi tui cũng vậy
Xóa