1. 程式人生 > >Java 圖形使用者介面-向JApplet新增元件

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);
	}
}