第十一周课程总结
话不多说,上代码!!!
package demo;
import java.awt.*;
import java.awt.Font;
import java.io.File;
import javax.swing.*;
public class demo1 {
public static void main(String[] args) {
JFrame frame = new JFrame("welcome to 小新新私人窗口"); //容器名
frame.setLayout(new FlowLayout(FlowLayout.CENTER,30,30));
String picpath="E:"+File.separator+"picture"+File.separator+"1.png";
String pic1path="E:"+File.separator+"picture"+File.separator+"3.jpg";
//Icon icon =new ImageIcon(picpath);
JLabel la=new JLabel(icon,JLabel.CENTER);
// la.getRootPane().setBackground(Color.black);
Icon icon1 =new ImageIcon(pic1path);
JLabel l=new JLabel(icon1,JLabel.CENTER);//
frame.add(la);
frame.add(l);
JLabel lab =new JLabel("腾讯QQ",JLabel.LEFT); // 标签的设置
Font fnt =new Font("微软雅黑",Font.ITALIC+Font.BOLD,20); //字体设置
lab.setFont(fnt);
lab.setForeground(new Color(100,100,120));
frame.add(lab);
Dimension dim = new Dimension(300,200);
//dim.setSize(200,70);
frame.setSize(dim);
frame.getContentPane().setBackground(new Color(255,200,255));
Point point = new Point(300,200);
frame.setLocation(point);
frame.setVisible(true);
}
}
package demo;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Demo04 {
public static void main(String[] args) {
JFrame frame =new JFrame("welcome to 小新新窗口");
frame.setLayout(new BorderLayout(3,3));
frame.add(new JButton("东 (EAST) "),BorderLayout.EAST);
frame.add(new JButton("西 (WEST) "),BorderLayout.WEST);
frame.add(new JButton("南 (SOUTH) "),BorderLayout.SOUTH);
frame.add(new JButton("北 (NORTH) "),BorderLayout.NORTH);
frame.add(new JButton("中 (CENTER) "),BorderLayout.CENTER);
frame.pack();
frame.setSize(200,300);
frame.setLocation(200,100);
frame.getContentPane().setBackground(new Color(0,230,150));
frame.setVisible(true);
}
}
package demo;
import java.awt.*;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Demo03 {
public static void main(String[] args) {
JFrame frame =new JFrame("welcome to 小新新私密窗口");
frame.setLayout(new GridLayout(3,5,3,3));
JButton but =null;
for(int i=0;i<13;i++)
{
but=new JButton("按钮-"+i);
frame.add(but);
}
frame.pack();
frame.setVisible(true);
frame.setSize(500,500);
frame.setLocation(200,100);
frame.getContentPane().setBackground(new Color(0,120,255));
}
}
package demo;
import java.io.*;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.*;
public class test {
public static void main(String[] args) {
JFrame frame =new JFrame("welcome to 小新新私人窗口");
Container cont=frame.getContentPane();
CardLayout card =new CardLayout();
frame.setLayout(card);
frame.setSize(500,400);
frame.setLocation(200,100);
cont.add(new JLabel(new ImageIcon("E:"+File.separator+"picture"+File.separator+"1.jpg"),JLabel.CENTER),"first");
cont.add(new JLabel(new ImageIcon("E:"+File.separator+"picture"+File.separator+"2.jpg"),JLabel.CENTER),"second");
cont.add(new JLabel(new ImageIcon("E:"+File.separator+"picture"+File.separator+"3.jpg"),JLabel.CENTER),"third");
cont.add(new JLabel(new ImageIcon("E:"+File.separator+"picture"+File.separator+"4.jpg"),JLabel.CENTER),"fourth");
cont.add(new JLabel(new ImageIcon("E:"+File.separator+"picture"+File.separator+"5.jpg"),JLabel.CENTER),"fifth");
frame.pack();
frame.setVisible(true);
card.show(cont,"first");
for(int i=0;i<5;i++)
{
try {
Thread.sleep(2000);
}catch(Exception e)
{
}
card.next(cont);
}
}
}
package demo;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class demo02 {
public static void main(String[] args) {
JFrame frame =new JFrame("welcome to 私人窗口");
frame.setLayout(null);
JLabel user =new JLabel("用户名");
JLabel pass =new JLabel("密码");
JLabel A=new JLabel("登录");
JLabel B=new JLabel("注册");
JTextField jtfuser=new JTextField();
JPasswordField jpfpass =new JPasswordField();
user.setBounds(10,10,50,20);
jtfuser.setBounds(80,10,100,20);
pass.setBounds(10,50,50,20);
jpfpass.setBounds(80,50,100,20);
A.setBounds(30,90,20,20);
B.setBounds(90,90,20,20);
frame.add(user);
frame.add(pass);
frame.add(jtfuser);
frame.add(jpfpass);
frame.add(A);
frame.add(B);
frame.setSize(400,300);
frame.setVisible(true);
}
}
这是我对本周所学java图形界面中容器,组件,布局管理器的简单操作,也是对于本周所写的代码的复习吧!!
本周学习总结
1.对于AWT与swing的了解,主要的区别就是跨区域性。
2.主要是对swing图形界面的了解(其必须导入javax.swing包中),在界面中利用JFrame容器装标签(JLabel),再利用布局管理器进行对部件的排放位置进行调整(布局管理器分为FlowLayout,BorderLayout,GridLayout,CardLayout,绝对定位),对于他们我就对CardLayout与绝对定位有意思,就比如我可以放上我喜欢的照片进行翻阅,只是说利用按钮操作进行翻阅还在努力思考中,还有就是看到很多网页的登录都基本利用了绝对定位这样我就可以设置属于自己的登录页面。