Java 图形用户界面-向JApplet添加组件

/**
作者:wwj
日期:2012/4/15
功能:实现在JApplet中添加组件
**/

import javax.swing.*;
import java.awt.*;
import java.awt.Color;

public class JAp extends JApplet
{
	Container c;
	JPanel p1,p2;
	JButton button1,button2,button3;
	JLabel label;

	public void init()
	{
		c=getContentPane();
		p1=new JPanel(new FlowLayout());
		p2=new JPanel(new FlowLayout());
		ImageIcon icon=new ImageIcon("image/first_16x16.gif"," ");
		button1=new JButton(icon);
		button2=new JButton(new ImageIcon("image/ok_16x16.gif"));
		button3=new JButton(new ImageIcon("image/down_16x16.gif"));
		label=new JLabel("图像标签",
			new ImageIcon("image/100.jpg"),SwingConstants.CENTER);

		c.setBackground(new Color(255,255,204));
		p1.setBackground(new Color(255,255,204));
		p2.setBackground(new Color(255,255,204));

		button1.setToolTipText("向上翻页按钮");
		button2.setToolTipText("跳转按钮");
		button3.setToolTipText("向下翻页按钮");

		c.add(p1,BorderLayout.NORTH);
		c.add(p2,BorderLayout.SOUTH);
		p1.add(button1);
		p1.add(button2);
		p1.add(button3);
		p2.add(label);
	}
}

posted on 2012-04-15 16:57  1.曲待续  阅读(275)  评论(0编辑  收藏  举报

导航