⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkboard.java

📁 square array cool stuff check it out
💻 JAVA
字号:
/** * Name:   Carl Finch * Project:  Checkboard Chapter 5  * Date:    01\03\05 * My Purpose:  To create the project in the book with the least minimuim lines of code as possible. */import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.text.*;import java.lang.*;import javax.swing.JFrame;import java.lang.String.*;public class Checkboard extends JApplet implements ActionListener{    //Global variables declared    int start =0;    int stop =0;    int  step =0;    JTextArea[]  MyTextFieldArray = new JTextArea[16];    JTextField[] MyTextFields = new JTextField[3];    Color myBlue = new Color(0, 250 ,100);                                //MainPanel where we add to content and MyArrayPanel is where the text arrays will be, and mystart    //is the panels where the editable textfields will be    JPanel MainPanel = new JPanel();    JPanel MyArrayPanel = new JPanel();    JPanel MyStart = new JPanel();    JPanel MyStop = new JPanel();           //Textfields, and labels needed for application    //JLabel lblEdit = new JLabel("Edit Text Area's");    JLabel lblStart = new JLabel("Start");    JLabel lblStop = new JLabel("Stop");    JLabel lblStep = new JLabel("Step");    JLabel lblGuess = new JLabel("Guess the code");    JLabel lblSkip = new JLabel("\t\t\t\t\t\t\t");    JButton btnGo = new JButton("Go");    JButton btnReset = new JButton("Reset");    JButton btnRandomizer = new JButton("Randomize");                public void init()    {                      //Loop to add the textarea's        for(int c=0; c<=15; c++)        {            MyTextFieldArray[c] = new JTextArea(3, 5);            MyArrayPanel.add(MyTextFieldArray[c]);            MyTextFieldArray[c].setText("" +c);             MyTextFieldArray[c].setEditable(false);                                           }                        MyStop.add(lblGuess);                        MyStart.add(lblStart);            MyTextFields[0] = new JTextField(10);            MyStart.add(MyTextFields[0]);            MyStart.add(lblStop);            MyTextFields[1] = new JTextField(10);            MyStart.add(MyTextFields[1]);            MyStart.add(lblStep);            MyTextFields[2] = new JTextField(10);            MyStart.add(MyTextFields[2]);            MyStart.add(lblSkip);            MyStart.add(btnGo);            MyStart.add(btnReset);            btnGo.addActionListener(this);            btnReset.addActionListener(this);            //MyStart.add(btnRandomizer);           // btnRandomizer.addActionListener(this);                                Container content = getContentPane();        content.setLayout((new BorderLayout()));        MainPanel.add(MyStop);        MainPanel.add(MyArrayPanel);        MainPanel.add(MyStart);                MyStop.setLayout(new FlowLayout());        MyArrayPanel.setLayout(new GridLayout(4, 4, 4, 4));        MyStart.setLayout(new GridLayout(9,1));        MainPanel.setLayout(new FlowLayout());        content.add(MainPanel);                        //Create GUI to look good        content.setBackground(Color.black);        content.setForeground(Color.white);        MainPanel.setBackground(Color.black);        MyStart.setBackground(Color.black);        MyStart.setForeground(Color.white);        btnGo.setBackground(Color.white);        btnGo.setForeground(Color.red);        MyArrayPanel.setBackground(Color.black);        lblStart.setForeground(Color.red);        lblStop.setForeground(Color.red);        lblStep.setForeground(Color.red);        lblSkip.setForeground(Color.white);        btnReset.setForeground(Color.red);        btnReset.setBackground(Color.white);    }          public void actionPerformed(ActionEvent e)    {        start = Integer.parseInt(MyTextFields[0].getText());        stop = Integer.parseInt(MyTextFields[1].getText());        step = Integer.parseInt(MyTextFields[2].getText());                       if(e.getSource() == btnRandomizer)        {            for(int x=start; x<=stop; x-=step)            {                MyTextFieldArray[x].setBackground(Color.red);            }        }                        if(e.getSource() == btnReset)        {            MyTextFields[0].setText("");            MyTextFields[1].setText("");            MyTextFields[2].setText("");                     for(int x=0; x<=16; x++)         {          MyTextFieldArray[x].setText("");          MyTextFieldArray[x].setBackground(Color.white);         }                 }              if(e.getSource() == btnGo)       {           if(step==1)           {           for(int x=start; x<=stop; x+=step)           {               MyTextFieldArray[x].setBackground(Color.blue);            }                    }           if(step==2)           {           for(int x=start; x<=stop; x+=step)           {               MyTextFieldArray[x].setBackground(Color.red);            }    }                if(step==3)           {           for(int x=start; x<=stop; x+=step)           {               MyTextFieldArray[x].setBackground(Color.green);            }    }                if(step==4)           {           for(int x=start; x<=stop; x+=step)           {               MyTextFieldArray[x].setBackground(Color.yellow);            }    }        if(step>=5)           {           for(int x=start; x<=stop; x+=step)           {               MyTextFieldArray[x].setBackground(Color.orange);                           }    }                                    }        if(step<=-1)    {        JOptionPane.showMessageDialog(null, "Can't have a negative increment");         MyTextFields[0].setText("");         MyTextFields[1].setText("");         MyTextFields[2].setText("");                      }    if(stop<start)    {        JOptionPane.showMessageDialog(null, "Can't stop less than you started");         MyTextFields[0].setText("");         MyTextFields[1].setText("");         MyTextFields[2].setText("");                      }        if(stop>=16)    {        JOptionPane.showMessageDialog(null, "Can't go out of the bounds of 16 squares");         MyTextFields[0].setText("");         MyTextFields[1].setText("");         MyTextFields[2].setText("");                      }    }    }                                                                                                    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -