📄 fontpanel.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.JTextArea;
import java.awt.datatransfer.*;
import java.io.*;
import java.awt.datatransfer.*;
import javax.swing.*;
import javax.swing.border.*;
class FontPanel extends Panel implements ItemListener
{
List list;
Box baseBox,boxH1,boxH2,boxH3,boxH4,boxH5;
List fontList;
List sizeList;
TextField fontText;
TextField sizeText;
static JTextArea exampleText;
static int size=20;
int tempsize=20;
static String name="character list";
FontPanel()
{
setLayout(new BorderLayout());
Color c=new Color(236,233,216);
this.setBackground(c);
Panel p1=new Panel();
boxH1=Box.createHorizontalBox();
Label charterLabel=new Label("字体");
charterLabel.setAlignment(1);
boxH1.add(charterLabel);
boxH1.add(Box.createHorizontalStrut(1));
Label sizeLabel=new Label("大小");
sizeLabel.setAlignment(1);
boxH1.add(sizeLabel);
boxH2=Box.createHorizontalBox();
fontText=new TextField(8);
boxH2.add(fontText);
boxH2.add(Box.createHorizontalStrut(1));
sizeText=new TextField(8);
boxH2.add(sizeText);
fontList=new List(6,false);
fontList.addItemListener(this);
GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
String fontName[]=ge.getAvailableFontFamilyNames();
for(int i=0;i<fontName.length;i++)
{
fontList.add(fontName[i]);
}
sizeList=new List(6,false);
sizeList.addItemListener(this);
for(int i=8;i<73;i++)
{
sizeList.add(String.valueOf(i));
}
Panel listpanel=new Panel();
GridLayout g2=new GridLayout(1,2);
listpanel.setLayout(g2);
listpanel.add(fontList);
listpanel.add(sizeList);
boxH4=Box.createHorizontalBox();
Label exampleLabel=new Label("示例");
exampleLabel.setAlignment(1);
boxH4.add(exampleLabel);
boxH4.add(Box.createHorizontalStrut(1));
exampleText=new JTextArea(1,1);
exampleText.append("Welcom to YONA studio!!");
boxH4.add(exampleText);
GridLayout g1=new GridLayout(2,1);
p1.setLayout(g1);
p1.add(boxH1);
p1.add(boxH2);
GridLayout g3=new GridLayout(2,1);
Panel p2=new Panel();
p2.setLayout(g3);
p2.add(boxH4);
add(p1,BorderLayout.NORTH);
add(listpanel,BorderLayout.CENTER);
add(p2,BorderLayout.SOUTH);
this.setVisible(true);
this.setBounds(280,250,300,150);
this.validate();
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource()==fontList)
{
name=fontList.getSelectedItem();
Font f=new Font(name,Font.PLAIN,tempsize);
exampleText.setFont(f);
fontText.setText(name);
}
if(e.getSource()==sizeList)
{
size=Integer.parseInt(sizeList.getSelectedItem());
tempsize=size;
Font f=new Font(fontList.getSelectedItem(),Font.PLAIN,tempsize);
exampleText.setFont(f);
sizeText.setText(String.valueOf(size));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -