通过这学期的java课,我学到了不少东西,特别是那些稀奇古怪的程序,更是令我好奇,开始学java课,看着那本很厚的java教材,个我的第一印象就是这门课程一定很难。但随着课程的慢慢深入,我就发现,其实吧,java课还是挺有趣的·,特别是后面所学的那些知识让我感觉这门课程在实际中的用处非常多,所以多多学习这门课程是非常有益的,特别是对考研的同学来说。当然那些我打出来的程序还是让我挺兴奋的:
随机数: public class mathrondom {public static void main(String[] args) {
for(int i=0;i<10;i++){ int s=1+(int)(Math.random()*(100-1)); System.out.println(s); } } }import java.awt.BorderLayout;
import java.awt.Color; import java.awt.GridLayout;import javax.swing.*;
public class keytef {
String[] k=new String[]{"7","8","9","/","4","5","6","*","1","2","3","-","0",".","=","+"}; JFrame j; JPanel P1,p2; JTextField t; JButton[] b=new JButton[16]; public keytef(){ j=new JFrame("计算器"); t=new JTextField(100); p2=new JPanel(new GridLayout(4,4)); p2.setBackground(Color.red); for(int i=0;i<16;i++){ b[i]=new JButton(k[i]); p2.add(b[i]); } j.add(t,BorderLayout.NORTH); j.add(p2); j.setSize(300, 200); j.setLocation(300,400); j.setVisible(true); }public static void main(String[] args) {
new keytef();}
}import java.awt.Color;
import java.awt.event.ActionEvent; import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JFrame; import javax.swing.JPanel;public class keysst implements ActionListener{
JFrame j; JButton b1,b2,b3,b4; JPanel p; public keysst(){ j=new JFrame(); p=new JPanel(); b1=new JButton("红色"); b1.addActionListener(new bread1()); b2=new JButton("绿色"); b2.addActionListener(new bread2()); b3=new JButton("蓝色"); b3.addActionListener(new bread3()); b4=new JButton("灰色"); b4.addActionListener(this); p.setBackground(Color.lightGray); p.add(b1); p.add(b2); p.add(b3); p.add(b4); j.add(p); j.setSize(400, 300); j.setLocation(200, 300); j.setVisible(true); }public static void main(String[] args) {
new keysst();}
public class bread1 implements ActionListener{
@Override public void actionPerformed(ActionEvent e) { p.setBackground(Color.red);}
}public class bread2 implements ActionListener{
@Override public void actionPerformed(ActionEvent e) { p.setBackground(Color.green);}
}public class bread3 implements ActionListener{
@Override public void actionPerformed(ActionEvent e) { p.setBackground(Color.blue);}
}@Override
public void actionPerformed(ActionEvent e) { p.setBackground(Color.lightGray);}
}总的来说,这门课程还是听令我兴奋的,希望能多多接触这门课程,去学习更多。