⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sw1.java.bak

📁 swing.rar
💻 BAK
字号:
/*
SWINGS
	Look & Feel

	Java controls looks like MS-Controls

	Java's Front-end Tool

	javax.swing.*		package

Applet/Frames				Swings

Frame					JFrame
Applet					JApplet
TextField				JTextField
Button					JButton
Choice					JComboBox
Checkbox				JRadioButton
						ButtonGroup
.
.
.

JButton
	class
	For clicking purpose

cons:
	JButton()
	JButton(String Label)
	JButton(String Label,ImageIcon)

	ImageIcon	
		Class
		Used to load the images to the required component
	cons:
		ImageIcon(String path)

JFrame
	Class
	Its a container		Its a Window

Cons:
	JFrame()
	JFrame(String Title)

Methods:
	setTitle(String Title)
	getTitle()				String
	setLayout(Layout)
	setMenuBar(Menubarobjname)
	setSize(int width,int height)
	setVisible(boolean)

	java.awt.*	package
	java.awt.Container	Class
			Base class to all Gui Tools
			Abstract Class
		Method:
			getContentPane()	ret	Container


//	Container con = new Container();	// abs cls can't be created

	Container con = getContentPane();
*/

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

class sw1 extends JFrame implements ActionListener
{
	JButton b1 = new JButton("Ok");
	JButton b2 = new JButton("Cancel");
	JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER));

	public sw1()
	{
		Container con = getContentPane();
			con.add(b1);
			con.add(b2);
			p1.add(b1);
			p1.add(b2);
			con.add(p1);
			b1.addActionListener(this);
			b2.addActionListener(this);
			setTitle("Demo");
		setSize(300,300);
		setVisible(true);
	}
     
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource() == b1)
		{
			System.out.println("Button b1 is pressed");
		}
		else
		{
			System.out.println("Button b2 is pressed");
		}
	}

	public static void main(String args[])
	{
		new sw1();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -