如果你pc上有这写字体的话,就可以显示
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class test1
extends JFrame
implements ActionListener {
JTextArea text;
JButton button1, button2, button3;
public test1() {
super("aa");
Container c = getContentPane();
c.setLayout(new FlowLayout());
text = new JTextArea("中国人", 5, 10);
button1 = new JButton("正体");
button2 = new JButton("斜体");
button3 = new JButton("粗体");
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
c.add(new JScrollPane(text));
c.add(button1);
c.add(button2);
c.add(button3);
text.setFont(new Font("宋体", Font.PLAIN, 13));
setSize(300, 200);
show();
} public void actionPerformed(ActionEvent e) {
if (e.getSource() == button1) {
text.setFont(new Font("华文彩云", Font.PLAIN, 13));
text.setForeground(Color.red);
System.out.println(1);
}
else if (e.getSource() == button2) {
text.setFont(new Font("宋体", Font.ITALIC, 13));
System.out.println(2);
}
else if (e.getSource() == button3) {
text.setFont(null);
text.setFont(new Font("黑体", Font.BOLD, 13));
System.out.println(3);
}
} public static void main(String args[]) {
test1 cz = new test1();
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class test1
extends JFrame
implements ActionListener {
JTextArea text;
JButton button1, button2, button3;
public test1() {
super("aa");
Container c = getContentPane();
c.setLayout(new FlowLayout());
text = new JTextArea("中国人", 5, 10);
button1 = new JButton("正体");
button2 = new JButton("斜体");
button3 = new JButton("粗体");
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
c.add(new JScrollPane(text));
c.add(button1);
c.add(button2);
c.add(button3);
text.setFont(new Font("宋体", Font.PLAIN, 13));
setSize(300, 200);
show();
} public void actionPerformed(ActionEvent e) {
if (e.getSource() == button1) {
text.setFont(new Font("华文彩云", Font.PLAIN, 13));
text.setForeground(Color.red);
System.out.println(1);
}
else if (e.getSource() == button2) {
text.setFont(new Font("宋体", Font.ITALIC, 13));
System.out.println(2);
}
else if (e.getSource() == button3) {
text.setFont(null);
text.setFont(new Font("黑体", Font.BOLD, 13));
System.out.println(3);
}
} public static void main(String args[]) {
test1 cz = new test1();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货