import java.awt.BorderLayout;
成都創(chuàng)新互聯(lián)是一家專(zhuān)業(yè)從事網(wǎng)站建設(shè)、網(wǎng)絡(luò)營(yíng)銷(xiāo)、小程序設(shè)計(jì)、網(wǎng)站運(yùn)營(yíng)為一體的建站企業(yè);在網(wǎng)站建設(shè)告別千篇一律,告別似曾相識(shí),這一次我們重新定義網(wǎng)站建設(shè),讓您的網(wǎng)站別具一格。自適應(yīng)網(wǎng)站建設(shè),實(shí)現(xiàn)全網(wǎng)營(yíng)銷(xiāo)!一站適應(yīng)多終端,一樣的建站,不一樣的體驗(yàn)!
import java.awt.CardLayout;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
public class MainFrame extends JFrame implements ActionListener{
InsertPanel ip = null;
SelectPanel sp = null;
JPanel pframe;
JButton jb1,jb2,jb3;
JMenuItem jm11,jm21,jm22,jm23,jm31,jm32,jm41,jm42;
CardLayout clayout;
public MainFrame(String s){
super(s);
JMenuBar mb = new JMenuBar();
this.setJMenuBar(mb);
JMenu m1 = new JMenu("系統(tǒng)");
JMenu m2 = new JMenu("基本信息");
JMenu m3 = new JMenu("成績(jī)");
JMenu m4 = new JMenu("獎(jiǎng)懲");
mb.add(m1);
mb.add(m2);
mb.add(m3);
mb.add(m4);
jm11 = new JMenuItem("退出系統(tǒng)");
jm21 = new JMenuItem("輸入");
jm22 = new JMenuItem("查詢(xún)");
jm23 = new JMenuItem("更改");
jm31 = new JMenuItem("輸入成績(jī)");
jm32 = new JMenuItem("查詢(xún)成績(jī)");
jm41 = new JMenuItem("獎(jiǎng)勵(lì)");
jm42 = new JMenuItem("處分");
m1.add(jm11);
m2.add(jm21);
m2.add(jm22);
m2.add(jm23);
m3.add(jm31);
m3.add(jm32);
m4.add(jm41);
m4.add(jm42);
Icon i1 = new ImageIcon();
Icon i2 = new ImageIcon();
Icon i3 = new ImageIcon();
jb1 = new JButton(i1);
jb1.setToolTipText("輸入");
jb2 = new JButton(i2);
jb2.setToolTipText("查詢(xún)");
jb3 = new JButton(i3);
jb3.setToolTipText("退出");
JToolBar tb = new JToolBar("系統(tǒng)工具");
tb.add(jb1);
tb.add(jb2);
tb.add(jb3);
add(tb,BorderLayout.NORTH);
jm11.addActionListener(this);
jm21.addActionListener(this);
jm22.addActionListener(this);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
clayout = new CardLayout();
pframe = new JPanel(clayout);
add(pframe);
JPanel mainp = new JPanel(new BorderLayout());
JLabel mainl = new JLabel("學(xué)生信息管理平臺(tái)",SwingConstants.CENTER);
mainl.setFont(new Font("serif",Font.BOLD,30));
mainp.add(mainl);
pframe.add(mainp,"main");
clayout.show(pframe, "main");
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == jm21 || e.getSource() == jb1){
if(ip == null){
ip= new InsertPanel();
pframe.add(ip,"insert");
}
clayout.show(pframe, "insert");
this.setTitle("輸入學(xué)生信息");
}
else if(e.getSource() == jm22 || e.getSource() == jb2){
if(sp == null){
sp= new SelectPanel();
pframe.add(sp,"select");
}
clayout.show(pframe, "select");
this.setTitle("查詢(xún)學(xué)生信息");
}
else if(e.getSource() == jm11 || e.getSource() == jb3){
System.exit(0);
}
}
}
第二個(gè):
import javax.swing.JFrame;
public class MainTest {
public static void main(String [] args){
MainFrame f = new MainFrame("學(xué)生信息管理平臺(tái)");
f.setSize(400,300);
f.setLocation(350,250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
第二個(gè):
import java.sql.Connection;
import java.sql.DriverManager;
public class MySQLConnection {
static Connection getCon(){
Connection con = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/test","root","123");
}
catch(Exception e){
System.out.println("建立數(shù)據(jù)庫(kù)連接遇到異常!");
}
return con;
}
}
第四個(gè):
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
public class SelectPanel extends JPanel implements ActionListener{
JButton jb;
JTextField jt;
JTextField jt1,jt2,jt3,jt4;
public SelectPanel(){
JLabel jl = new JLabel("請(qǐng)輸入學(xué)號(hào):",SwingConstants.CENTER);
jt = new JTextField();
jb = new JButton("確定");
JPanel jp1 = new JPanel(new GridLayout(1,3));
jp1.add(jl);
jp1.add(jt);
jp1.add(jb);
JLabel j1,j2,j3,j4;
j1 = new JLabel("學(xué)號(hào):",SwingConstants.CENTER);
j2 = new JLabel("姓名:",SwingConstants.CENTER);
j3 = new JLabel("性別:",SwingConstants.CENTER);
j4 = new JLabel("年齡:",SwingConstants.CENTER);
jt1 = new JTextField(6);
jt1.setEditable(false);
jt2 = new JTextField(6);
jt2.setEditable(false);
jt3 = new JTextField(6);
jt3.setEditable(false);
jt4 = new JTextField(6);
jt4.setEditable(false);
JPanel jp2 = new JPanel(new BorderLayout());
JPanel jp3 = new JPanel(new GridLayout(4,2));
jp2.add(new JLabel(""),BorderLayout.NORTH);
jp3.add(j1);
jp3.add(jt1);
jp3.add(j2);
jp3.add(jt2);
jp3.add(j3);
jp3.add(jt3);
jp3.add(j4);
jp3.add(jt4);
jp2.add(jp3);
this.setLayout(new BorderLayout());
add(jp1,BorderLayout.NORTH);
add(jp2);
jb.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == jb){
String stuNo = jt.getText().trim();
Student s = new Student();
boolean b = true;
try{
b = s.selectByStuNo(stuNo);
}
catch(Exception ex){
System.out.println("查詢(xún)學(xué)生信息遇到異常!");
}
if(b){
jt1.setText(s.getStuNo());
jt2.setText(s.getName());
jt3.setText(s.getGender());
int a = s.getAge();
Integer i = new Integer(a);
jt4.setText(i.toString());
}
else{
JOptionPane.showMessageDialog(null, "無(wú)此學(xué)生!");
}
}
}
}
第五個(gè):
import javax.swing.JFrame;
public class SelectTest {
public static void main(String [] args){
JFrame f = new JFrame("查詢(xún)學(xué)生信息");
SelectPanel p = new SelectPanel();
f.add(p);
f.setSize(400,300);
f.setLocation(300,250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
第六個(gè):
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
public class Student {
String stuNo;
String name;
String gender;
int age;
public Student(){}
public Student(String stuNo,String name,String gender, int age){
this.stuNo = stuNo;
this.name = name;
this.gender = gender;
this.age = age;
}
public String getStuNo(){
return stuNo;
}
public void setStuNo(String stuNo){
this.stuNo = stuNo;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public String getGender(){
return gender;
}
public void setGender(String gender){
this.gender = gender;
}
public int getAge(){
return age;
}
public void setAge(int age){
this.age = age;
}
public boolean insertStudent(){
boolean b = true;
try{
Connection con = MySQLConnection.getCon();
Statement statement = con.createStatement();
String sql = "insert into student values('" + stuNo + "','" + name +"','" + gender + "'," + age + ")";
sql = new String(sql.getBytes("gb2312"),"ISO8859_1");
statement.executeUpdate(sql);
con.close();
}
catch(Exception e){
b = false;
System.out.println("插入數(shù)據(jù)庫(kù)遇到異常!");
}
return b;
}
public boolean selectByStuNo(String stuNo)throws Exception{
boolean b = true;
Connection con = MySQLConnection.getCon();
Statement statement = con.createStatement();
String sql = "select * from student where stuNo =" + stuNo;
ResultSet rs = statement.executeQuery(sql);
if(rs != null rs.next()){
String no = rs.getString(1);
this.setStuNo(no);
String n = rs.getString(2);
n = new String(n.getBytes("ISO8859_1"),"gb2312");
this.setName(n);
String g = rs.getString(3);
g = new String (g.getBytes("ISO8859_1"),"gb2312");
this.setGender(g);
this.setAge(rs.getInt(4));
b = true;
}
rs.close();
statement.close();
con.close();
return b;
}
}
數(shù)據(jù)庫(kù)你自己弄吧,我沒(méi)時(shí)間弄了!初學(xué)得多動(dòng)手哦
Java 程序員必須收藏的資源大全
古董級(jí)工具
這些工具伴隨著Java一起出現(xiàn),在各自輝煌之后還在一直使用。
Apache Ant:基于XML的構(gòu)建管理工具。
cglib:字節(jié)碼生成庫(kù)。
GlassFish:應(yīng)用服務(wù)器,由Oracle贊助支持的Java EE參考實(shí)現(xiàn)。
Hudson:持續(xù)集成服務(wù)器,目前仍在活躍開(kāi)發(fā)。
JavaServer Faces:Mojarra是JSF標(biāo)準(zhǔn)的一個(gè)開(kāi)源實(shí)現(xiàn),由Oracle開(kāi)發(fā)。
JavaServer Pages:支持自定義標(biāo)簽庫(kù)的網(wǎng)站通用模板庫(kù)。
Liquibase:與具體數(shù)據(jù)庫(kù)獨(dú)立的追蹤、管理和應(yīng)用數(shù)據(jù)庫(kù)Scheme變化的工具。
2.構(gòu)建工具
構(gòu)建及應(yīng)用依賴(lài)關(guān)系處理工具。
Apache Maven:Maven是一款聲明式構(gòu)建及依賴(lài)管理工具,采用約定優(yōu)于配置方式進(jìn)行管理。相對(duì)Apache Ant更推薦使用Maven,前者采用了過(guò)程式管理,維護(hù)相對(duì)困難。
Bazel:來(lái)自Google的構(gòu)建工具,可以快速、可靠地構(gòu)建代碼。
Gradle:使用Groovy(非XML)進(jìn)行增量構(gòu)建,可以很好地與Maven依賴(lài)管理配合工作。
需要這些學(xué)習(xí)資料和工具的可以自己下載哦
package test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpTest {
private String u;
private String encoding;
public static void main(String[] args) throws Exception {
HttpTest client = new HttpTest("", "UTF-8");
client.run();
}
public HttpTest(String u, String encoding) {
this.u = u;
this.encoding = encoding;
}
public void run() throws Exception {
URL url = new URL(u);// 根據(jù)鏈接(字符串格式),生成一個(gè)URL對(duì)象
HttpURLConnection urlConnection = (HttpURLConnection) url
.openConnection();// 打開(kāi)URL
BufferedReader reader = new BufferedReader(new InputStreamReader(
urlConnection.getInputStream(), encoding));// 得到輸入流,即獲得了網(wǎng)頁(yè)的內(nèi)容
String line; // 讀取輸入流的數(shù)據(jù),并顯示
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
}
}
根據(jù)具體問(wèn)題類(lèi)型,進(jìn)行步驟拆解/原因原理分析/內(nèi)容拓展等。
具體步驟如下:/導(dǎo)致這種情況的原因主要是……
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
public class game21 extends JFrame {
private JLabel label_2;
private int number;
private int sum;
final JLabel label = new JLabel();
final JLabel label_1 = new JLabel();
public static void main(String[] args) {
new game21();
}
public game21() {
super("21點(diǎn)?!");
getContentPane().setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg0) {
onClick();
}
});
button.setText("出牌");
button.setBounds(170, 350, 106, 28);
getContentPane().add(button);
label.setBorder(new LineBorder(Color.black, 1, false));
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setFont(new Font("", Font.BOLD, 26));
label.setText("背面");
label.setBounds(158, 81, 137, 153);
getContentPane().add(label);
label_1.setText("你已經(jīng)擁有的牌:");
label_1.setBounds(109, 22, 270, 45);
getContentPane().add(label_1);
this.setBounds(200, 300, 501, 528);
this.setVisible(true);
getContentPane().add(getLabel_2());
}
public int randNumber() {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
return (int) (Math.random() * 10 + 1);
}
public void onClick() {
number = this.randNumber();
this.sum += number;
label.setText("" + number);
String strTemp = this.label_1.getText();
strTemp += "" + number + " ";
label_1.setText(strTemp);
String temp = "合計(jì):" + sum;
label_2.setText(temp);
isWin();
}
public void isWin() {
if (sum 21) {
JOptionPane.showMessageDialog(this, "你輸了");
clear();
return;
} else if (sum == 21) {
JOptionPane.showMessageDialog(this, "你贏了");
clear();
return;
} else {
int i = JOptionPane.showOptionDialog(this, "是否繼續(xù)?", "提示",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, null, null);
if (i == JOptionPane.OK_OPTION) {
onClick();
} else
return;
}
}
private void clear() {
label_2.setText("合計(jì):");
sum = 0;
number = 0;
label_1.setText("你已經(jīng)擁有的牌:");
}
/**
* @return
*/
protected JLabel getLabel_2() {
if (label_2 == null) {
label_2 = new JLabel();
label_2.setText("合計(jì):");
label_2.setBounds(313, 35, 66, 18);
}
return label_2;
}
}
真好無(wú)聊中。。