1.程式碼
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends JFrame{
public static void main(String[]args){
JFrame window=new JFrame("Calculator");
JPanel jplPanel = new JPanel();
JButton button[]=new JButton[10];
for(int i=0;i<button.length;i++){
button[i] = new JButton();
button[i].setSize(50,50);
button[i].setText(Integer.toString(i+1));
jplPanel.add(button[i]);
}
window.getContentPane().add(jplPanel, BorderLayout.CENTER);
window.setSize(500,500);
window.setVisible(true);
}}
2.完成圖
沒有留言:
張貼留言