猜猜看游戏框架
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.SystemColor;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
public class caa extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField tfDir;
private JTextField tfClass;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
caa frame = new caa();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public caa() {
setTitle("\u731C\u731C\u770B\u6E38\u620FV0.1");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 645, 409);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
// 选择目录 按钮的处理程序
JButton btnDir = new JButton("\u9009\u62E9\u76EE\u5F55");
btnDir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JFileChooser jfc=new JFileChooser();
jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES );
jfc.showDialog(new JLabel(), "选择");
File file=jfc.getSelectedFile();
if(file.isDirectory()){
System.out.println("文件夹:"+file.getAbsolutePath());
}else if(file.isFile()){
System.out.println("文件:"+file.getAbsolutePath());
}
System.out.println(jfc.getSelectedFile().getName());
// 把文件路径显示在文本框中
tfDir.setText(file.getAbsolutePath());
}
});
btnDir.setBounds(26, 26, 93, 23);
contentPane.add(btnDir);
// 文本框,显示目录
tfDir = new JTextField();
tfDir.setEditable(false);
tfDir.setBounds(125, 27, 363, 21);
contentPane.add(tfDir);
tfDir.setColumns(10);
// 选择班级 按钮的处理程序
JButton btnClass = new JButton("\u9009\u62E9\u73ED\u7EA7");
btnClass.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
btnClass.setBounds(26, 59, 93, 23);
contentPane.add(btnClass);
// 文本框,显示班级文件
tfClass = new JTextField();
tfClass.setEditable(false);
tfClass.setBounds(125, 60, 363, 21);
contentPane.add(tfClass);
tfClass.setColumns(10);
// 标签,显示带猜测学生姓名
JLabel lbGuessName = new JLabel("\u59D3\u540D");
lbGuessName.setBounds(259, 91, 102, 23);
contentPane.add(lbGuessName);
// 标签,显示第一个学生相片
JLabel lblImg1 = new JLabel("\u56FE\u72471");
lblImg1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
}
});
lblImg1.setBounds(26, 151, 183, 178);
contentPane.add(lblImg1);
// 标签,显示第二个学生相片
JLabel lblImg2 = new JLabel("\u56FE\u72472");
lblImg2.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
}
});
lblImg2.setForeground(Color.BLACK);
lblImg2.setBackground(SystemColor.inactiveCaption);
lblImg2.setBounds(241, 155, 183, 172);
contentPane.add(lblImg2);
// 标签,显示第三个学生相片
JLabel lblImg3 = new JLabel("\u56FE\u72473");
lblImg3.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
}
});
lblImg3.setBounds(434, 155, 185, 172);
contentPane.add(lblImg3);
// 再猜一次 按钮,点击则更新相应的三张图片 与 带猜测学生姓名
JButton btnGuessAgain = new JButton("\u518D\u731C\u4E00\u6B21");
btnGuessAgain.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
btnGuessAgain.setBounds(223, 337, 93, 23);
contentPane.add(btnGuessAgain);
}
}
}
问题一:简述Java中,连接数据库有哪几个基本步骤? 其相应的核心类与代码分别是什么?
答:Java中,连接数据库的基本步骤包括:第一步:下载一个JDBC驱动包,例如:mysql-connector-java-5.1.17-bin.jar;第二步:导入下载的JDBC驱动包,我用的是myeclipse,选中自己要导包的项目,右 击选中propertise,再选JavaBuild Path, 右边会出现libreries,点进去,再点Add External JARs 然后再找到你要导入的驱动包。完了之后再点Order andExport,下面再选中你导入的包。
第三步:加载驱动程序:Class.forName("com.mysql.jdbc.Driver");
第四步:连接数据库:Connection conn=DriverManager.getConnection ("jdbc:mysql://localhost/数据库名称","root","123456");
第五步:声明一个Statement 用来执行sql语句: Statement stmt=conn.createStatement();
第六步:声明一个结果集接住执行sql语句的数据: ResultSet rs=stmt.executeQuery("select * from 表名");
附:完整的数据库连接(链接)
问题二:简述MySQL中,创建一个数据表的SQL语句是什么?
答:create table pageindex(url varchar(200), connent varchar(200), offset int, raws varchar(200)); 插入数据
insert into pageindex values("http://www.163.com/","2013-10-12",1011,"8292323");
问题三: 简述Java中,生成[1,53]之间的随机数的核心代码分别是什么?
答:
import java.util.Random;
public class Radom{
public static void main(String[] strs){
Random rand = new Random(53);
}
问题四:简述Java中,读写文本文件的类分别是什么?核心代码分别是什么?
答:BufferedReader类 (链接