这里写目录标题
一级目录
二级目录
三级目录
第一部分3.5
使用 ecplise
语言 Java
1.安装jdk
2.解压eclipse并进行设置
3.安装mysql
4.安装mysql的前端软件navicat
1.1 创建一个窗口
下面展示一些 内联代码片
。
package sias;
import javax.swing.*;//导入窗口
public class MyFrame extends JFrame{
//继承窗口类
public MyFrame()//构造函数
{
setTitle("我爱你中国");
setSize(600,400);
setVisible(true);//设置窗口可见性
}
public static void main(String[] args) {
// TODO Auto-generated method stub
MyFrame my1 = new MyFrame();
//my1.show();
my1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置窗口正常关闭
}
}
更换图标 设置流式布局
完成–>图片被放在标签上 标签被添加在内容窗格里,左上角有图片图标
下面展示一些 内联代码片
。
package sias;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Image;
import javax.swing.*;//导入窗口类
import javax.swing.ImageIcon;//导入图片类
public class MyFrame extends JFrame{
//继承窗口类
public MyFrame()//构造函数
{
setTitle("我爱你中国");
ImageIcon icon1 = new ImageIcon("image\\hx.jpg");//创建图片对象
Image image1 = icon1.getImage();//创建image对象
setIconImage(image1);//设置图片到窗口左上角
JLabel label1 = new JLabel(icon1);//参数不能是图片类对象可以是图标
Container c1 = getContentPane();//得到内容窗格
c1.setLayout(new FlowLayout());//设置流式布局
c1.add(label1);//添加标签
setSize(600,400);
setVisible(true);//设置窗口可见性
}
public static void main(String[] args) {
// TODO Auto-generated method stub
MyFrame my1 = new MyFrame();
//my1.show();
my1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置窗口正常关闭
}
}
1.2 创建窗口控件及子窗口
完成目标1
下面展示一些 内联代码片
。
package sias;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Image;
//导入图片类
import javax.swing.*;//导入窗口类
public class MyFrame extends JFrame{
//继承窗口类
//定义所需要的的控件
JLabel labelname;
JTextField textname;
JLabel labeltall;
JTextField tall1;
JLabel labelweight;
JTextField weight1;
JLabel labelhome;
JTextField home1;
JLabel labelpwd;
JPasswordField pwd1;
JButton button1;//按钮
public MyFrame()//构造函数
{
setTitle("我爱你中国");
ImageIcon icon1 = new ImageIcon("image\\hx.jpg");//创建图片对象
Image image1 = icon1.getImage();//创建image对象
setIconImage(image1);//设置图片到窗口左上角
//JLabel label1 = new JLabel(icon1);//参数不能是图片类对象可以是图标
Container c1 = getContentPane();//得到内容窗格
c1.setLayout(new FlowLayout());//设置流式布局
//c1.add(label1);//添加标签
labelname = new JLabel("name");
textname = new JTextField(15);//宽度为10
labeltall = new JLabel("tall");
tall1 = new JTextField(15);
labelweight = new JLabel("weight");
weight1 = new JTextField(15);
labelhome = new JLabel("home");
home1 = new JPasswordField(15);
labelpwd = new JLabel("password");//创建密码标签
pwd1 = new JPasswordField(15);
button1 =new JButton("确定");
//c1得到当前窗口内容窗格 用add函数添加到c1窗口上
c1.add(labelname);
c1.add(textname);
c1.add(labeltall);
c1.add(tall1);
c1.add(labelweight);
c1.add(weight1);
c1.add(labelhome);
c1.add(home1);
c1.add(labelpwd);
c1.add(pwd1);
c1.add(button1);
setSize(