发布时间 : 星期二 文章Java课程设计更新完毕开始阅读597df54df7ec4afe04a1dfbe
Java课程设计
{
this.ext = ext; }
public boolean accept(File file) {
if (file.isDirectory()) return true;
String fileName = file.getName(); int index = fileName.lastIndexOf('.');
if (index > 0 && index < fileName.length()-1) {
String
extension
fileName.substring(index+1).toLowerCase(); if (extension.equals(ext)) return true; }
return false; }
public String getDescription(){ if (ext.equals(\
return \记事本文件(*.txt)\ return \ }
}
class Win extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0);
}
} 内容三:
第21页 共33页
=
Java课程设计
import java.awt.*; import java.awt.event.*;
class WindowButton extends Frame implements ActionListener {
int r,n1,n2,n3,count1=0,count2=0; Label 提示条,label; TextField text1,text2,text3; Button button1; Button button2; WindowButton(String s) { super(s);
this.setSize(270, 180); setLayout(new FlowLayout()) ; label=new Label();
//label.setBackground(Color.cyan); add(label);
提示条=new Label(\输入试验次数\ 提示条.setBackground(Color.cyan); add(提示条);
text3=new TextField(\ add(text3);
button1=new Button(\方案1(猜1次)\ button2=new Button(\方案2(猜2次)\ text1=new TextField(20); text2=new TextField(20); add(button1); add(button2); add(text1);
第22页 共33页
Java课程设计
add(text2); label=new Label();
//label.setBackground(Color.cyan); add(label);
button1.addActionListener(this); button2.addActionListener(this); text1.addActionListener(this); text2.addActionListener(this); //setBounds(100,100,150,150); setVisible(true); validate();
addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) {
System.exit(0); } }); }
public void actionPerformed(ActionEvent e) {int n=0; try{
n=Integer.parseInt(text3.getText()); }
catch(NumberFormatException event) {
label.setText(\请输入数字字符!\}
if(e.getSource()==button1)
第23页 共33页
Java课程设计
{
for(int i=0;i r=(int)(Math.random()*3)+1; n1=(int)(Math.random()*3)+1; if(r==n1) count1++; } text1.setText(\方案1的正确次数:\ } if(e.getSource()==button2) { for(int i=0;i r=(int)(Math.random()*3)+1; n1=(int)(Math.random()*3)+1; do { n2=(int)(Math.random()*3)+1; } while(n2==n1 || n2==r); do { n3=(int)(Math.random()*3)+1; } while(n3==n2); if(n3==r) count2++; } 第24页 共33页