📄 appletdemo2.java
字号:
//Example 2 of Chapter 6
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class AppletDemo2 extends JApplet implements ActionListener
{
Container container;
JButton BackButton, ForeButton, ResetButton;
JLabel text;
Color color1 = Color.lightGray;
Color color2 = Color.black;
public void init()
{
container = getContentPane();
container.setLayout(new FlowLayout());
text = new JLabel("show a JColorChooser Using", SwingConstants.CENTER );
text.setFont( new Font( "Dialog", Font.BOLD, 24));
BackButton = new JButton("调整背景色");
ForeButton = new JButton("调整前景色");
ResetButton = new JButton("重置颜色");
BackButton.addActionListener(this);
ForeButton.addActionListener(this);
ResetButton.addActionListener(this);
container.add( text );
container.add( BackButton );
container.add( ForeButton );
container.add( ResetButton );
}
public void actionPerformed( ActionEvent event )
{
if( event.getSource() == BackButton )
{
color1 = JColorChooser.showDialog( this, "选择颜色", color1);
if( color1 == null ) color1 = Color.lightGray;
container.setBackground( color1 );
}
if( event.getSource() == ForeButton )
{
color2 = JColorChooser.showDialog( this, "选择颜色", color2);
if(color2 == null)color2 = Color.black;
text.setForeground( color2 );
}
if( event.getSource() == ResetButton )
{
color1 = Color.lightGray;
container.setBackground( color1 );
color2 = Color.black;
text.setForeground( color2 );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -