i 绝望

依然

Miss Lang

Swing编程练习。可能这篇会有错误哦

总结:21岁的思思是华为的初级女java工程师,我等女流怎么办呢?

Swing。图形用户界面的编程,panel起了很大作用

package com.da;

import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.BorderLayout;
//将图片放入框架,
import javax.swing.ImageIcon;

public class loi {
	public static void main(String[] args) {
		JFrame frame = new JFrame("a啊啊啊啊");
		Container c = frame.getContentPane();
		c.setLayout(new GridLayout(4, 2));// 这里不new GridLayout()会报错。
		JPanel imagepanel1 = new JPanel();
		imagepanel1.setLayout(new BorderLayout());
		// JPanel imagepanel3=new JPanel();
		// imagepanel3.setLayout(new BorderLayout());//这是面板的布局方式的创建。new....懂不?
		// JPanel imagepanel3=new JPanel(new
		// BorderLayout());//这里是因为。布局管理器方式,需要方法setLayout();//设置成边界布局
		JPanel imagepanel3 = new JPanel(new BorderLayout());
		JPanel imagepanel2 = new JPanel(new BorderLayout());
		imagepanel3.add(c, BorderLayout.CENTER);// 这里imagepanel3直接调用方法BorderLayout
		ImageIcon image1 = new ImageIcon("iamg/3.jpg");
		ImageIcon image2 = new ImageIcon("iamg/2.jpg");
		JLabel l = new JLabel("太阳照常升起");
		JLabel l2 = new JLabel("大家平安");
		c.add(l2);// 将标签添加到内容窗格中,
		c.add(l);
		// 把图片放入标签里面----因为要放图片,所以一定有标签
		l.setIcon(image1);// 这个命名很棘手,总是不懂的,图片标签
		l2.setIcon(image2);// 为什么要一个面板放一个标签???
		imagepanel1.add(l, BorderLayout.NORTH);
		imagepanel2.add(l2, BorderLayout.WEST);
		JButton south = new JButton("South");
		south.setFont(new Font("dfasd", Font.BOLD, 44));
		// c.add(b);//只有这么搞??不知放哪个面板里???
		JLabel la = new JLabel("大家一起比赛吧", JLabel.CENTER);// 对于普通的标签布局方法是自己的类调用内支付方法。
		// la.add(new Font("",Font.BOLD,43));
		la.setFont(new Font("Serif", Font.BOLD, 42));
		la.setForeground(Color.red);
		l.setFont(new Font("Serif", Font.BOLD, 42));// 先创建对象,再给对象赋值
		frame.add("south", south);
		frame.add(imagepanel1, BorderLayout.NORTH);
		frame.add(imagepanel2, BorderLayout.WEST);
		frame.add(imagepanel3, BorderLayout.SOUTH);
		frame.setBounds(533, 466, 555, 555);
		frame.setVisible(true);

	}
}

  

 

posted on 2013-11-18 21:29  juewang  阅读(241)  评论(0编辑  收藏  举报

绝望依然

Miss Lang