网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

java代码窗口化,如何让程序窗口化

Java怎样写出Windows窗口化程序??

import javax.swing.JOptionPane;

创新互联专业为企业提供泰兴网站建设、泰兴做网站、泰兴网站设计、泰兴网站制作等企业网站建设、网页设计与制作、泰兴企业网站模板建站服务,十多年泰兴做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

class Test {

public static long function(int n)throws Exception{

if(n==0){

return 1;

}else{

return n*function(n-1);

}

}

public static void main(String[] args)throws Exception {

String whole=JOptionPane.showInputDialog("请输入一个整数!");

int n=0;

long l=0;

try{

n=Integer.parseInt(whole);

if(n1)

throw new NumberFormatException();

}catch(NumberFormatException e){

JOptionPane.showMessageDialog(null, "您输入的不是一个正整数!");

}

l= function(n);

JOptionPane.showMessageDialog(null,l);

}

}

java如何操作窗口化程序

给一个登录的,不错,我用的

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

/*

APPLET

CODE=dialoginput.class

WIDTH=300

HEIGHT=200

/APPLET

*/

public class dialoginput extends JApplet implements ActionListener

{

JLabel top=new JLabel("Welcome to cn-java net !");

JButton display=new JButton("会员登录");

JLabel welcomeword=new JLabel(" 您还没有登录 ");

JLabel title=new JLabel(" 登 录 窗 口 "),

name=new JLabel("会员名:"),

password=new JLabel("密码:");

JTextField inputname=new JTextField(12);

JPasswordField inputpassword=new JPasswordField(12);//与AWT不同的是,Swing有一个用于口令的特殊控件,就是JPasswordField

JButton ok=new JButton("确定"),

cancel=new JButton("放弃");

private JDialog dialog=new JDialog((Frame)null,"登录",true);

public void init()

{

Container contentPane=getContentPane();

Container dialogContentPane=dialog.getContentPane();

JPanel p=new JPanel();

contentPane.setLayout(new GridBagLayout());

GridBagConstraints gbc=new GridBagConstraints();

gbc.gridy=0;

contentPane.add(top,gbc);

gbc.gridx=GridBagConstraints.RELATIVE;

gbc.gridy=1;

contentPane.add(display,gbc);

gbc.gridx=GridBagConstraints.RELATIVE;

gbc.gridy=2;

contentPane.add(welcomeword,gbc);

dialogContentPane.setLayout(new GridBagLayout());

GridBagConstraints gbb=new GridBagConstraints();

gbb.gridx=1;

gbb.gridy=0;

dialogContentPane.add(title,gbb);

gbb.gridx=GridBagConstraints.RELATIVE;

gbb.gridy=1;

dialogContentPane.add(name,gbb);

dialogContentPane.add(inputname,gbb);

gbb.gridx=GridBagConstraints.RELATIVE;

gbb.gridy=2;

dialogContentPane.add(password,gbb);

dialogContentPane.add(inputpassword,gbb);

inputpassword.setEchoChar('*');

gbb.gridx=GridBagConstraints.RELATIVE;

gbb.gridy=3;

p.setLayout(new FlowLayout());

p.add(ok);

p.add(cancel);

gbb.gridx=1;

gbb.gridy=4;

dialogContentPane.add(p,gbb);

display.addActionListener(this);

ok.addActionListener(this);

cancel.addActionListener(this);

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==display){

dialog.setBounds(200,200,300,200);

dialog.show();

}else if(e.getSource()==ok){

welcomeword.setText("您好,"+inputname.getText()+",欢迎光临中文Java技术网!");

}else if(e.getSource()==cancel){

welcomeword.setText("你没有输入!");

}

dialog.setVisible(false);

}

}

我在eclipse上用java编了一小段代码,用来显示一个简单的窗口,程序可以运行,但看不到出现窗口,怎么办?

我给你写个方法,你可以比着葫芦画个瓢,好吧、

注:在编写这样的小窗口时要主要几点

1、在构造函数里设置窗体的(位置和)大小,用this.setBounds(int x,int y,int width,int height);实现

2、设置窗体的可见性,一般这句代码写在构造函数的末尾,用this.setVisible(true);实现,少了这句代码,窗体是看不到的

3、这一点对于非常简单的窗体不是满重要,用this.SetDefaultCloseOperation(EXIT_ON_CLOSE);设置当点击窗体的"*"(差,退出按钮时),退出程序,少了这句代码,程序默

认是隐藏窗体。

*******************************************************************************************

package com.xpsoft.swingtest;//导入包

import java.awt.Color;//导入标题栏的Icon图片包

import javax.swing.*;//导入JFrame所在的包

import java.awt.FlowLayout;//导入布局管理器包(初学者可以暂时不做关注)

public class Swing1 extends JFrame{

/**

* @param args

*/

public Swing1(){//无参构造函数

this.setTitle("我的第一个Frame");

this.setLayout(null);//可以暂时设为Null布局:new FlowLayout()

this.setBounds(450,150,500,400);//没有这一步,窗体默认最小化,在电脑屏幕的左上角处

this.setResizable(false);//禁止修改Frame的大小(可以不设置)

//this.setUndecorated(true);//去掉窗体的边框和标题栏

this.setVisible(true);//把窗体设为可以(非常重要)

//关闭窗体时执行的4种操作

this.setDefaultCloseOperation(EXIT_ON_CLOSE);//关闭该窗体

/*this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);//不做任何操作

this.setDefaultCloseOperation(HIDE_ON_CLOSE);//隐藏窗体(默认)

this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);//释放窗体对象*/

}

public static void main(String[] args) {

Swing1 s=new Swing1();

/*JFrame frame=new JFrame();

frame.setTitle("直接使用JFrame创建窗体");

frame.setBounds(450,150,500,400);

frame.setVisible(true);*/

}

}

**************************************************************

希望能够对你有所帮助哦

用C语言和Java编写一个窗口化程序,用哪个语言实现更简单些?

用C语言实现就比较复杂了,首先你要有C语言的基础,在这之上你可以写一些没有界面的逻辑性代码,假如你想要学习写界面,很悲催的告诉你,你需要学一个MFC的东西,这个东西就是用C,C++实现界面程序的,它是C++的一个类库,然后你要用它写出一个界面,你还需要一个不是特别容易的学习过程;

总之MFC是属于比较过时,复杂的东西了;

而java相对来说就特别容易了,楼上提到的C#,我觉得和java差不多。

窗口可见代码怎么打java

jframe.setVisible(true) 即可让窗口可见.

API里关于该方法的说明

public void setVisible(boolean b)

根据参数 b 的值显示或隐藏此 Window。

窗口的其他常用属性的设置,详细见下面的例子

示例图

参考代码和详细的注释

import java.awt.Color;

import java.awt.Font;

import javax.swing.JFrame;

import javax.swing.JLabel;

public class MyFrame extends JFrame {

//构造函数

public MyFrame() {

JLabel jl = new JLabel("床前明月光,疑是地上霜。",JLabel.CENTER);//文字标签,文字居中

jl.setForeground(Color.BLUE);//文字的颜色

jl.setFont(new Font("仿宋", Font.BOLD, 20));//设置文字,字体

add(jl);//把文字添加到窗口

//getContentPane().setBackground(Color.WHITE); //设置窗口(内容面板)的背景颜色

setTitle("窗口示例");// 窗口标题

setSize(300, 200);// 窗口大小 宽300 高200

setLocationRelativeTo(null);// 窗口居中

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 当窗口关闭时,程序结束

}

//main函数

public static void main(String[] args) {

MyFrame frame = new MyFrame();// 创建窗口

frame.setVisible(true);// 让该窗口实例可见

}

}


当前文章:java代码窗口化,如何让程序窗口化
当前链接:http://bjjierui.cn/article/dsejejd.html

其他资讯