?? fontdialog.java
字號(hào):
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class Fontdialog extends JDialog implements ListSelectionListener,ActionListener{
Container contentPane = this.getContentPane();
JLabel word = new JLabel("字體(F):");
JLabel wordx = new JLabel("字形(Y):");
JLabel bs = new JLabel("大小(s):");
JTextField f1 = new JTextField();
JTextField f2 = new JTextField();
JTextField f3 = new JTextField();
JTextField fsl = new JTextField("魔帥出品");
JList l1 = new JList();
JList l2 = new JList();
JList l3 = new JList();
JScrollPane p1 = new JScrollPane(l1);
JScrollPane p2 = new JScrollPane(l2);
JScrollPane p3 = new JScrollPane(l3);
JPanel sl = new JPanel();
JButton Enter = new JButton("確定");
JButton quxiao = new JButton("取消");
Font font1 = new Font("Fixedsys",Font.PLAIN,12);
Font font2 = new Font("Fixedsys",Font.PLAIN,12);
String selName = f1.getText(), selFontx = f2.getText(), selBs;
Fontdialog(JiShiBen ben, String string, boolean b){
super(ben,string,b);
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e){}
init();
this.setSize(440,325);
this.setResizable(false);
this.setLayout(null);
this.setLocationRelativeTo(null);
}
void init(){
l1.addListSelectionListener(this);
l2.addListSelectionListener(this);
l3.addListSelectionListener(this);
contentPane.add(word);
contentPane.add(wordx);
contentPane.add(bs);
contentPane.add(f1);
contentPane.add(f2);
contentPane.add(f3);
contentPane.add(p1);
contentPane.add(p2);
contentPane.add(p3);
contentPane.add(Enter);
contentPane.add(quxiao);
contentPane.add(sl);
contentPane.setBackground(Color.WHITE);
word.setLocation(10,5);
word.setSize(50,20);
wordx.setLocation(165,5);
wordx.setSize(50,20);
bs.setLocation(280,5);
bs.setSize(50,20);
f1.setLocation(10,25);
f1.setSize(150,20);
f1.setText("Fixedsys");
GraphicsEnvironment g1 = GraphicsEnvironment.getLocalGraphicsEnvironment();
String [] fontName = g1.getAvailableFontFamilyNames();//獲取windows的字體
l1.setListData(fontName);
f2.setLocation(165,25);
f2.setSize(110,20);
f2.setText("常規(guī)");
String []fontx = {"常規(guī)","斜體","粗體","粗斜體"};
l2.setListData(fontx);
f3.setLocation(280,25);
f3.setSize(50,20);
f3.setText("12");
String [] fontbs = {"8","9","10","11","12","14","16","18","20","22","24","26","28","36","48","72"};
l3.setListData(fontbs);
p1.setHorizontalScrollBar(null);//去掉下面的滾動(dòng)條
p1.setLocation(10,45);
p1.setSize(150,90);
p2.setHorizontalScrollBar(null);
p2.setLocation(165,45);
p2.setSize(110,90);
p3.setHorizontalScrollBar(null);
p3.setLocation(280,45);
p3.setSize(50,90);
Enter.setLocation(345,25);
Enter.setSize(70,20);
quxiao.setLocation(345,50);
quxiao.setSize(70,20);
sl.setLocation(165,155);
sl.setSize(165,80);
sl.setLayout(new BorderLayout());
sl.add(fsl,BorderLayout.CENTER);
sl.setBorder(BorderFactory.createTitledBorder("示例"));
fsl.setSize(100,20);
fsl.setHorizontalAlignment(JTextField.CENTER);
Enter.addActionListener(this);
quxiao.addActionListener(this);
}
public void valueChanged(ListSelectionEvent e) {
if(e.getSource() == l1){
selName = (String)l1.getSelectedValue();
f1.setText(selName);
this.My_Font();
}else if(e.getSource() == l2){
selFontx = (String)l2.getSelectedValue();
f2.setText(selFontx);
this.My_Font();
}else if(e.getSource() == l3){
selBs = (String)l3.getSelectedValue();
f3.setText(selBs);
this.My_Font();
}
fsl.setFont(font1);
}
public void My_Font(){
if(selFontx == "常規(guī)"){
font1 = new Font(selName,Font.PLAIN,Integer.parseInt(f3.getText()));
}else if(selFontx=="斜體"){
font1 = new Font(selName,Font.ITALIC,Integer.parseInt(f3.getText()));
}else if(selFontx=="粗體"){
font1 = new Font(selName,Font.BOLD,Integer.parseInt(f3.getText()));
}else if(selFontx=="粗斜體"){
font1 = new Font(selName,Font.ITALIC+Font.BOLD,Integer.parseInt(f3.getText()));
}
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()=="確定"){
font2 = font1;
this.setDefaultCloseOperation(HIDE_ON_CLOSE);
}else{
this.setDefaultCloseOperation(HIDE_ON_CLOSE);
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -