📄 miukono4.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
import java.awt.datatransfer.*;//用于打开文件和保存文件的一个类
import java.applet.Applet;
import java.awt.geom.*;
import sun.audio.*;
import java.sql.*;
import javax.swing.*;
class miukoNO4 extends Frame implements ActionListener
{
private Image img;
boolean bo=false;
private int jn=0,jj=0;
private int n,m=0,y1=72,k=0;
private Connection con;//定义一个能连接数据库的变量
private Statement stmt;
private ResultSet rs;
private TextField t[],t1,t2[],t3[],t4;
private Button b1,b2,b3,b4,b5,b6,b[];
private Label g1,g[];
private String st1[],st2[],st3[],st4[],st5[],str[],s[],ss,sn[];
String strr1,strr2,strr3,strr4,strr5;
Color c1,c2,c3;
miukoNO4()
{
super("~NO.4~~默写英文");
Toolkit tool = getToolkit();
img = tool.getImage("Bingo.jpg");
c1 = new Color(0,173,173);
c2 = new Color(210,0,133);
c3 = new Color(225,135,0);
setBackground(c1);
setSize(400,624);
setIconImage(img);
setLayout(null);
setLocation(300,60);
miuko();
b1 = new Button("重选单元");
b1.setBounds(11,51,90,20);
b1.setBackground(c1);
b1.addActionListener(this);
add(b1);
b1.setVisible(true);
b2 = new Button("校正结果");
b2.setBounds(107,51,90,20);
b2.setBackground(c1);
b2.addActionListener(this);
add(b2);
b2.setVisible(true);
b3 = new Button("返回主页");
b3.setBounds(203,51,90,20);
b3.setBackground(c1);
b3.addActionListener(this);
add(b3);
b3.setVisible(true);
b4 = new Button("退出软件");
b4.setBounds(300,51,90,20);
b4.setBackground(c1);
b4.addActionListener(this);
add(b4);
b4.setVisible(true);
b5 = new Button("上一页");
b5.setBounds(10,598,90,20);
b5.setBackground(c1);
b5.addActionListener(this);
add(b5);
b5.setVisible(true);
b6 = new Button("下一页");
b6.setBounds(300,598,90,20);
b6.addActionListener(this);
b6.setBackground(c1);
add(b6);
b6.setVisible(true);
t1 = new TextField("第"+n+"单元共有"+m+"个单词");
t1.setBounds(10,30,189,20);
t1.setBackground(c1);
add(t1);
t1.setVisible(true);
t4 = new TextField("一共有"+k+"页");
t4.setBounds(201,30,189,20);
t4.setBackground(c1);
add(t4);
t4.setVisible(true);
setVisible(true);
}
private void miuko()
{
int h=0;
int p=102;
String sj;
m = 0;
Color cc,cc1;
try
{
sj = JOptionPane.showInputDialog("请输入要默写的单元:");
if(String.valueOf(sj).equals("0"))
{
ok x=new ok("单元数不能为0");
x.setBackground(c2);
x.b1.setBackground(c2);
x.setLocation(390,280);
x.setVisible(true);
n = 1;
}
if(String.valueOf(sj).equals(""))
{
ok x=new ok("请先正确的输入单元数");
x.setBackground(c2);
x.b1.setBackground(c2);
x.setLocation(390,280);
x.setVisible(true);
n = 1;
}
else
n = Integer.parseInt(sj);
}
catch(Exception er){}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:miukou");
stmt = con.createStatement();
try
{
rs = stmt.executeQuery("SELECT * FROM miuko1 WHERE number="+n);
while(rs.next()&&(Integer.parseInt(rs.getString("number"))==n))
{
m=m+1;
}
rs.close();
}
catch(Exception e9){}
}
catch(Exception eeee){}
k = (m/25+1);
b=new Button[k];
for(int i = 0;i<k;i++)
{
b[i] = new Button("第"+(i+1)+"页");
b[i].setBounds(p,598,200/k,20);
b[i].addActionListener(this);
b[i].setBackground(c1);
add(b[i]);
b[i].setVisible(true);
p += 200/k+2;
}
st1 = new String[m];
st2 = new String[m];
st3 = new String[m];
st4 = new String[m];
st5 = new String[m];
sn = new String[m];
str = new String[m];
s = new String[m];
try
{
rs = stmt.executeQuery("SELECT * FROM miuko1 WHERE number="+n);
while(rs.next()&&(Integer.parseInt(rs.getString("number"))==n))
{
strr1=rs.getString("mean1");
strr2=rs.getString("mean2");
strr3=rs.getString("mean3");
strr4=rs.getString("mean4");
strr5=rs.getString("mean5");
if(strr2.equals("-"))
{
sn[h] =strr1;
}
else if(strr3.equals("-"))
{
sn[h] =strr1+","+strr2;
}
else if(strr4.equals("-"))
{
sn[h] =strr1+","+strr2+","+strr3;
}
else if(strr5.equals("-"))
{
sn[h] =strr1+","+strr2+","+strr3+","+strr4;
}
else if(!strr5.equals("-"))
{
sn[h] =strr1+","+strr2+","+strr3+","+strr4+","+strr5;
}
h++;
}
rs.close();
}
catch(Exception e9){}
g = new Label[m];
t = new TextField[m];
t2 = new TextField[m];
t3 = new TextField[m];
miuko:for( int i = 0; i < m; i++)
{
if(i%2==1)
{
cc = new Color(155,75,230);
cc1 = Color.green;
}
else
{
cc1 = new Color(155,75,230);
cc = Color.green;
}
g[i] = new Label(sn[i]);
g[i].setBackground(cc);
g[i].setForeground(Color.blue);
g[i].setBounds(10,y1,160,20);
g[i].setVisible(true);
add(g[i]);
t[i] = new TextField();
t[i].setBackground(cc);
t[i].setForeground(Color.blue);
t[i].setBounds(172,y1,97,20);
t[i].setVisible(true);
add(t[i]);
t2[i] = new TextField();
t2[i].setBackground(cc1);
t2[i].setForeground(Color.red);
t2[i].setBounds(271,y1,20,20);
add(t2[i]);
t2[i].setVisible(true);
t3[i] = new TextField();
t3[i].setBackground(cc);
t3[i].setForeground(Color.blue);
t3[i].setBounds(293,y1,97,20);
add(t3[i]);
t3[i].setVisible(true);
y1=y1+21;
if(y1 > 596)
{
y1=72;
t2[i].setVisible(false);
t3[i].setVisible(false);
t[i].setVisible(false);
g[i].setVisible(false);
}
}
}
public void actionPerformed(ActionEvent e)
{
for(int i = 0;i<k;i++)
{
if(e.getSource()==b[i])
{
for(int j=0;j<m;j++)
{
t2[j].setVisible(false);
t3[j].setVisible(false);
t[j].setVisible(false);
g[j].setVisible(false);
}
if(m>i*25+25)
{
for(int w=i*25;w<i*25+25;w++)
{
t2[w].setVisible(true);
t3[w].setVisible(true);
t[w].setVisible(true);
g[w].setVisible(true);
}
}
else
{
for(int w=i*25;w<m;w++)
{
t2[w].setVisible(true);
t3[w].setVisible(true);
t[w].setVisible(true);
g[w].setVisible(true);
}
}
jn = i;
jj = i;
}
}
if(e.getSource()==b4)
{
bo=false;
if(bo!=true)
{
bo=true;
miukook y=new miukook("确定要推出吗");
y.setBackground(c3);
y.b1.setBackground(c3);
y.b2.setBackground(c3);
y.setLocation(390,280);
y.setVisible(true);
}
}
if(e.getSource()==b3)
{
miuko0 f = new miuko0();
f.setVisible(true);
setVisible(false);
}
if(e.getSource()==b2)
{
int h = 0,r =0;
for(int i= 0;i<m;i++)
{
str[i]=String.valueOf(t[i].getText().trim());
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:miukou");
stmt = con.createStatement();
try
{
rs = stmt.executeQuery("SELECT * FROM miuko1 WHERE number="+n);
while(rs.next()&&(Integer.parseInt(rs.getString("number"))==n))
{
t3[r].setText(rs.getString("word"));
r++;
}
rs.close();
}
catch(Exception e9){}
}
catch(Exception eeee){}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:miukou");
stmt = con.createStatement();
try
{
r=0;
rs = stmt.executeQuery("SELECT * FROM miuko1 WHERE number="+n);
while(rs.next()&&(Integer.parseInt(rs.getString("number"))==n))
{
if(String.valueOf(t[h].getText().trim()).equalsIgnoreCase(rs.getString("word"))||String.valueOf(t[h].getText().trim()).equalsIgnoreCase(rs.getString("mean2"))||String.valueOf(t[h].getText().trim()).equalsIgnoreCase(rs.getString("mean3"))||String.valueOf(t[h].getText().trim()).equalsIgnoreCase(rs.getString("mean4"))||String.valueOf(t[h].getText().trim()).equalsIgnoreCase(rs.getString("mean5")))
{
t2[h].setText("√");
r++;
}
else
t2[h].setText("X");
h++;
}
rs.close();
}
catch(Exception e9){}
}
catch(Exception eeee){}
ok hh = new ok("答对"+r+"个,正确率"+(float)(100.0*r/m)+"%");
hh.setBackground(c2);
hh.b1.setBackground(c3);
hh.setLocation(390,280);
hh.setVisible(true);
}
if(e.getSource()==b1)
{
y1 = 72;
for(int i=0;i<k;i++)
{
b[i].setVisible(false);
}
for(int i=0;i<m;i++)
{
t2[i].setVisible(false);
t3[i].setVisible(false);
t[i].setVisible(false);
g[i].setVisible(false);
}
m=0;
miuko();
t4.setText("一共有"+k+"页");
t1.setText("第"+n+"单元共有"+m+"个单词");
}
if(e.getSource()==b5)
{
if(jn==0)
jn=0;
else
{
jj -=1;
jn -=1;
}
for(int j=0;j<m;j++)
{
t2[j].setVisible(false);
t3[j].setVisible(false);
t[j].setVisible(false);
g[j].setVisible(false);
}
if(m>jn*25+25)
{
for(int w=(jn)*25;w<(jn)*25+25;w++)
{
t2[w].setVisible(true);
t3[w].setVisible(true);
t[w].setVisible(true);
g[w].setVisible(true);
}
}
else
{
for(int w=(jn)*25;w<m;w++)
{
t2[w].setVisible(true);
t3[w].setVisible(true);
t[w].setVisible(true);
g[w].setVisible(true);
}
}
}
if(e.getSource()==b6)
{
if(jj==k-1)
jj=k-1;
else
{
jn +=1;
jj +=1;
}
for(int j=0;j<m;j++)
{
t2[j].setVisible(false);
t3[j].setVisible(false);
t[j].setVisible(false);
g[j].setVisible(false);
}
if(m>jj*25+25)
{
for(int w=(jj)*25;w<(jj)*25+25;w++)
{
t2[w].setVisible(true);
t3[w].setVisible(true);
t[w].setVisible(true);
g[w].setVisible(true);
}
}
else
{
for(int w=(jj)*25;w<m;w++)
{
t2[w].setVisible(true);
t3[w].setVisible(true);
t[w].setVisible(true);
g[w].setVisible(true);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -