/*********************************** 會考第一題:填圖程式 要用以下的方式執行系統才不會發生錯誤(增大stack memory) java -Xss20M b1 ************************************/ import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.io.*; import java.util.*; public class b1 extends b1pre implements ActionListener//按鈕事件 { Container c; JButton rot0,rot1; JRadioButton r_JRadioButton,g_JRadioButton,b_JRadioButton; ButtonGroup radiogroup = new ButtonGroup(); JLabel lab1=new JLabel("功能列表"); int mode=0; radioact RA1=new radioact(); int now_x,now_y; int clrpt=0,oldpt=0; static int cnt=0; public b1() //建構元 { super("填圖程式"); int i,j; c=getContentPane(); //設定buttom rot0=new JButton("結束"); //設定radio r_JRadioButton = new JRadioButton("red",true); g_JRadioButton = new JRadioButton("green"); b_JRadioButton = new JRadioButton("blue"); radiogroup.add(r_JRadioButton); radiogroup.add(g_JRadioButton); radiogroup.add(b_JRadioButton); //設定視窗大小 setSize(820,800); c.setLayout(new FlowLayout(FlowLayout.CENTER)); //裝設各種Adaptor c.add(lab1); c.add(rot0); c.add(r_JRadioButton); c.add(g_JRadioButton); c.add(b_JRadioButton); rot0.addActionListener(this); r_JRadioButton.addItemListener(RA1); g_JRadioButton.addItemListener(RA1); b_JRadioButton.addItemListener(RA1); addMouseListener(new cmouse()); show(); } public void paint(Graphics g) //真正的畫圖設定 { int x,y; super.paint(g); for (x=0;x=1) { if (getb_xy(x,y-1)==oldpt) fill(x,y-1); } if (y<=max_Y-2) { if (getb_xy(x,y+1)==oldpt) fill(x,y+1); } if (x>=1) { if (getb_xy(x-1,y)==oldpt) fill(x-1,y); } if (x<=max_X-2) { if (getb_xy(x+1,y)==oldpt) fill(x+1,y); } return; } //**********************/ public static void main(String args[]) //程式起點 { b1 app=new b1(); //畫圖 //處理視窗關閉要求 app.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);} }); } }