樓主,看java.io包里面的Serializable API 文檔和ObjectInputStream
公司主營業(yè)務(wù):成都網(wǎng)站設(shè)計、成都做網(wǎng)站、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴謹、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)推出沙雅免費做網(wǎng)站回饋大家。
ObjectOutputStream
package anfang;
import java.awt.*;
import java.awt.event.*;
public class example1 extends Frame{
Frame frm;
Button btn1,btn2,btn3,btn4;
TextField txt1,txt2,txt3;
public example1()
{
setLayout(null);
btn1 = new Button("+");
btn1.setLocation(55,55);
btn1.setSize(80,20);
class BtnClick implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
txt3.setText(""+(Integer.parseInt(txt1.getText())+Integer.parseInt(txt2.getText())));
}
}
BtnClick bc=new BtnClick();
btn1.addActionListener(bc);
add(btn1);
btn2 = new Button("-");
btn2.setLocation(50,100);
btn2.setSize(80,20);
class BtnClick1 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
txt3.setText(""+(Integer.parseInt(txt1.getText())-Integer.parseInt(txt2.getText())));
}
}
BtnClick1 bc1=new BtnClick1();
btn2.addActionListener(bc1);
add(btn2);
btn3 = new Button("*");
btn3.setLocation(50,150);
btn3.setSize(80,20);
class BtnClick2 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
txt3.setText(""+Integer.parseInt(txt1.getText())*Integer.parseInt(txt2.getText()));
}
}
BtnClick2 bc2=new BtnClick2();
btn3.addActionListener(bc2);
add(btn3);
btn4 = new Button("/");
btn4.setLocation(50,200);
btn4.setSize(80,20);
class BtnClick3 implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
txt3.setText(""+Integer.parseInt(txt1.getText())/Integer.parseInt(txt2.getText()));
}
}
BtnClick3 bc3=new BtnClick3();
btn4.addActionListener(bc3);
add(btn4);
txt1 = new TextField();
txt1.setLocation(200,60);
txt1.setSize(80,20);
add(txt1);
txt2 = new TextField();
txt2.setLocation(200,120);
txt2.setSize(80,20);
add(txt2);
txt3 = new TextField();
txt3.setLocation(200,180);
txt3.setSize(80,20);
add(txt3);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
example1 frm=new example1();
frm.setSize(450,300);
frm.show();
}
}
/** 希望 對你有用 同學(xué) 一個簡單而 但 很 實用的例子 */import java.awt. * ;
import java.awt.event. * ;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;public class swing extends JFrame { /**
* @param args
*/
JFrame j;
public swing() {
j = new JFrame("close windows");
j.setBounds(100, 100, 100, 100); // 設(shè)置 窗體 大小
j.getContentPane().setLayout(new FlowLayout(ABORT)); //設(shè)置 布局
JButton jbtn = new JButton();
jbtn.setText("退出");
jbtn.addMouseListener(new MouseAdapter(){ // 鼠標 監(jiān)聽 按下
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
System.exit(0);
super.mouseClicked(e);
}
});
j.add(jbtn); // 按鈕添加到 窗體
j.setVisible(true); // 設(shè)置窗體 可見
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run() {
// TODO Auto-generated method stub
new swing();
}
});
}
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class caishuzi extends JFrame implements ActionListener
{
private static final long serialVersionUID = 1L;
private JPanel textpanel, buttonpanel, fopanel, downpanel;
private JButton btn;
private JTextField jtinput, jttishi;
private JLabel lbnum0, lbnum, lbtishi, lbinput;
private JTextArea tafo;
private Boolean start = false, jisuan = false, jinru = false;
MenuBar mb = new MenuBar();
Menu filemenu = new Menu("文件"), systemmenu = new Menu("系統(tǒng)"),
helpmenu = new Menu("幫助");
MenuItem newfile = new MenuItem("文件"), openfile = new MenuItem("打開"),
closefile = new MenuItem("關(guān)閉"), quit = new MenuItem("退出"),
inputsecret = new MenuItem("輸入密碼"), help = new MenuItem("幫助"),
inputcishu = new MenuItem("輸入限制次數(shù)");
char[] c = new char[4];
String strsecret = "123";
int xianzhi=8;
caishuzi()
{
super("猜數(shù)字");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//this.setLocationRelativeTo(null);
// 設(shè)置菜單
filemenu.add(newfile);
filemenu.add(openfile);
filemenu.addSeparator();
filemenu.add(closefile);
newfile.setEnabled(false);
openfile.setEnabled(false);
closefile.setEnabled(false);
inputsecret.addActionListener(this);
inputcishu.addActionListener(this);
inputcishu.setEnabled(false);
systemmenu.add(inputsecret);
systemmenu.add(inputcishu);
systemmenu.add(quit);
quit.addActionListener(this);
help.addActionListener(this);
helpmenu.add(help);
mb.add(filemenu);
mb.add(systemmenu);
mb.add(helpmenu);
this.setMenuBar(mb);
Container c = this.getContentPane();
BorderLayout b = new BorderLayout();
b.setVgap(10);
c.setLayout(b);
settextpanel();
c.add(textpanel, BorderLayout.NORTH);
setbuttonpanel();
setfopanel();
setdownpanel();
c.add(downpanel, BorderLayout.CENTER);
this.setSize(680,350);
//this.setResizable(false);
//this.pack();
this.setVisible(true);
}
void settextpanel()
{
textpanel = new JPanel();
textpanel.setLayout(new FlowLayout());
lbinput = new JLabel("輸入:");
jtinput = new JTextField("", 10);
jtinput.setEditable(false);
jttishi = new JTextField(30);
lbnum = new JLabel("8");
lbnum0 = new JLabel("剩余次數(shù):");
lbtishi = new JLabel("提示:");
jttishi.setEditable(false);
textpanel.add(lbinput);
textpanel.add(jtinput);
textpanel.add(lbtishi);
textpanel.add(jttishi);
textpanel.add(lbnum0);
textpanel.add(lbnum);
}
void setbuttonpanel()
{
String[] str =
{ "7", "8", "9", "4", "5", "6", "1", "2", "3", "確定", "0", "退格" };
buttonpanel = new JPanel();
buttonpanel.setLayout(new GridLayout(4, 3, 4, 8));
for (int i = 0; i str.length; i++)
{
btn = new JButton(str[i]);
btn.addActionListener(this);
buttonpanel.add(btn);
}
}
void setfopanel()
{
JButton btnright = new JButton("正確答案");
JPanel p = new JPanel();
btnright.addActionListener(this);
fopanel = new JPanel();
fopanel.setLayout(new BorderLayout());
btn = new JButton("開始");
btn.addActionListener(this);
tafo = new JTextArea(15,12);
p.setLayout(new GridLayout(1, 2));
p.add(btn);
p.add(btnright);
fopanel.add(p, BorderLayout.NORTH);
tafo.setEditable(false);
fopanel.add(tafo, BorderLayout.CENTER);
}
void setdownpanel()
{
downpanel = new JPanel();
downpanel.setLayout(new GridLayout(1, 2, 30, 0));
downpanel.add(buttonpanel);
downpanel.add(fopanel);
}
public static void main(String[] args)
{
new caishuzi();
}
public void actionPerformed(ActionEvent e)
{
String s = e.getActionCommand();
if (s.equals("退出"))
{
int i = JOptionPane.showConfirmDialog(this, "確認退出?", "",
JOptionPane.YES_NO_OPTION);
//System.out.println(i);
if (i == 0)
{
System.exit(0);
}
}
if (s.equals("幫助"))
{
JOptionPane.showMessageDialog(this,
"猜數(shù)字游戲,可以輸入限制次數(shù),密碼為123,\n在菜單:系統(tǒng)——輸入密碼 中輸入!");
}
if (s.equals("輸入密碼"))
{
while (true)
{
String inputValue = "";
inputValue = JOptionPane.showInputDialog(this, "輸入密碼");
// System.out.println(inputValue);
if (inputValue == null)
return;
if (inputValue.equals(strsecret))
{
jinru = true;
jttishi.setText("密碼正確,點擊開始");
inputsecret.setEnabled(false);
break;
} else
{
int i = JOptionPane.showConfirmDialog(this, "密碼錯誤,重新輸入?",
"", JOptionPane.YES_NO_OPTION);
if (i == 1)
break;
}
}
}
if (!jinru)
{
jttishi.setText("請輸入密碼:");
return;
}
if (s.equals("開始") || s.equals("重玩"))
{
StringBuffer sb = new StringBuffer("0123456789");
for (int i = 0; i c.length; i++)
{
int n = (int) (Math.random() * sb.length());
c[i] = sb.charAt(n);
sb.deleteCharAt(n);
}
btn.setText("重玩");
start = true;
lbnum.setText(String.valueOf(xianzhi));
jisuan = false;
//System.out.println(c);
jttishi.setText("請輸入四不重復(fù)的數(shù):");
jtinput.setText("");
tafo.setText("");
}
if (s點抗 pareTo("0") = 0 s點抗 pareTo("9") = 0)
{
jisuan = false;
if (!start)
jttishi.setText("點擊開始!");
else
{
if (jtinput.getText().length() 4)
{
if (jtinput.getText().indexOf(s) 0)
{
jtinput.setText(jtinput.getText() + s);
if (jtinput.getText().length() 4)
jttishi.setText("還差"
+ (4 - jtinput.getText().length()) + "個數(shù)");
else
{
jttishi.setText("輸入正確,點擊確定");
jisuan = true;
}
} else
jttishi.setText("不能輸入重復(fù)的數(shù)");
} else
{
jttishi.setText("不能超過四個數(shù),點擊確定");
jisuan = true;
}
}
}
if (s.equals("退格") start)
{
if (jtinput.getText().length() 0)
{
jtinput.setText(jtinput.getText().substring(0,
jtinput.getText().length() - 1));
jttishi.setText("還差" + (4 - jtinput.getText().length()) + "個數(shù)");
}
jisuan = false;
}
if (s.equals("確定"))
{
if (!start)
{
jttishi.setText("還沒開始呢!");
return;
}
if (!jisuan)
{
jttishi.setText("輸入不正確!");
return;
}
int numa = 0, numb = 0;
char[] c1 = jtinput.getText().toCharArray();
// System.out.println(c1);
for (int i = 0; i c1.length; i++)
{
for (int j = 0; j c.length; j++)
{
if (c1[i] == c[j] i != j)
{
numb++;
}
if (c1[i] == c[j] i == j)
{
numa++;
}
}
}
tafo.append(jtinput.getText() + "\t" + numa + "A" + numb + "B"
+ "\n");
jtinput.setText("");
jisuan = false;
if (numa == 4)
{
jttishi.setText("答對了,再來一局吧!");
start = false;
btn.setText("開始");
tafo.append("恭喜,答對了! ");
} else
{
lbnum.setText(String
.valueOf(Integer.valueOf(lbnum.getText()) - 1));
if (Integer.valueOf(lbnum.getText()) == 0)
{
String str = "";
jttishi.setText("機會沒有了!很遺憾");
for (int i = 0; i c.length; i++)
str += c[i];
tafo.append("超過限制次數(shù),失敗!" + "正確答案是:" + str);
start = false;
btn.setText("開始");
} else
jttishi.setText("輸入四個數(shù):");
}
}
if (s.equals("正確答案"))
{
if (!start)
{
jttishi.setText("還沒開始呢!");
return;
}
String str = "";
for (int i = 0; i c.length; i++)
str += c[i];
tafo.append("正確答案是:" + str);
jttishi.setText("重新開始吧!");
start = false;
jisuan = false;
btn.setText("開始");
}
if (!start)
{
inputcishu.setEnabled(true);
} else
inputcishu.setEnabled(false);
if (s.equals("輸入限制次數(shù)"))
{
while (true)
{
try
{
String str = JOptionPane.showInputDialog(this,
"輸入小于15的整數(shù)數(shù)字:");
if (str == null)
return;
if (Integer.valueOf(str) = 15 Integer.valueOf(str) 0)
{
xianzhi=Integer.valueOf(str);
lbnum.setText(String.valueOf(xianzhi));
break;
} else
{
int i = JOptionPane.showConfirmDialog(this, "輸入錯誤,重試?",
"", JOptionPane.YES_NO_OPTION);
if (i == 1)
break;
}
} catch (Exception ex)
{
int i = JOptionPane.showConfirmDialog(this, "輸入錯誤,重試?", "",
JOptionPane.YES_NO_OPTION);
if (i == 1)
break;
}
}
}
}
}
我做課程設(shè)計的最初代碼 參考下吧 運行時先看幫助~
新聞標題:java窗體課程設(shè)計代碼 java窗口界面設(shè)計
分享網(wǎng)址:http://vcdvsql.cn/article28/ddeehjp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗、企業(yè)網(wǎng)站制作、網(wǎng)站改版、自適應(yīng)網(wǎng)站、微信小程序、網(wǎng)站設(shè)計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)