重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

java窗体课程设计代码 java窗口界面设计

JAVA课程设计报告:将当前窗体压缩成ZIP文件(附上源代码)。

楼主,看java.io包里面的Serializable API 文档和ObjectInputStream

公司主营业务:成都网站设计、成都做网站、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联推出沙雅免费做网站回馈大家。

ObjectOutputStream

java编程,设计一个窗体,要有三个部分(文本框、按钮、标签),按钮内容输出到文本框

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();

}

}

怎样用JAVA编程编写题目:设计一个窗体,在窗体中有个按钮,单击退出按钮,窗体消失

/** 希望 对你有用 同学 一个简单而 但 很 实用的例子 */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); // 设置 窗体 大小

j.getContentPane().setLayout(new FlowLayout(ABORT)); //设置 布局

JButton jbtn = new JButton();

jbtn.setText("退出");

jbtn.addMouseListener(new MouseAdapter(){ // 鼠标 监听 按下

public void mouseClicked(MouseEvent e) {

// TODO Auto-generated method stub

System.exit(0);

super.mouseClicked(e);

}

});

j.add(jbtn); // 按钮添加到 窗体

j.setVisible(true); // 设置窗体 可见

}

public static void main(String[] args) {

SwingUtilities.invokeLater(new Runnable(){

public void run() {

// TODO Auto-generated method stub

new swing();

}

});

}

java窗体猜数字代码

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("系统"),

helpmenu = new Menu("帮助");

MenuItem newfile = new MenuItem("文件"), openfile = new MenuItem("打开"),

closefile = new MenuItem("关闭"), quit = new MenuItem("退出"),

inputsecret = new MenuItem("输入密码"), help = new MenuItem("帮助"),

inputcishu = new MenuItem("输入限制次数");

char[] c = new char[4];

String strsecret = "123";

int xianzhi=8;

caishuzi()

{

super("猜数字");

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//this.setLocationRelativeTo(null);

// 设置菜单

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("剩余次数:");

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,

"猜数字游戏,可以输入限制次数,密码为123,\n在菜单:系统——输入密码 中输入!");

}

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("请输入四不重复的数:");

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()) + "个数");

else

{

jttishi.setText("输入正确,点击确定");

jisuan = true;

}

} else

jttishi.setText("不能输入重复的数");

} else

{

jttishi.setText("不能超过四个数,点击确定");

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()) + "个数");

}

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("超过限制次数,失败!" + "正确答案是:" + str);

start = false;

btn.setText("开始");

} else

jttishi.setText("输入四个数:");

}

}

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("输入限制次数"))

{

while (true)

{

try

{

String str = JOptionPane.showInputDialog(this,

"输入小于15的整数数字:");

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;

}

}

}

}

}

我做课程设计的最初代码 参考下吧 运行时先看帮助~


网站栏目:java窗体课程设计代码 java窗口界面设计
本文路径:http://cqcxhl.cn/article/ddeehjp.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP