?? format.java~44~
字號:
package jnotepad;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import com.borland.jbcl.layout.BoxLayout2;
import javax.swing.JLabel;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JTextField;
import javax.swing.JList;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import javax.swing.border.EtchedBorder;
import java.awt.Color;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import javax.swing.JTextArea;
import java.awt.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.MatteBorder;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* <p>Title: JNotePad</p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: hhxy</p>
*
* @author 王利華
* @version 1.0
*/
public class format extends JFrame {
JNotePadUI note;
String style;
int boldfont=Font.BOLD;
int italtcfont=Font.ITALIC;
int plainfont=Font.PLAIN;
int bifont=boldfont+italtcfont;
int font;
String fontname;
int size;
String list1[]={"Times New Roman","Dialog","Helvetica","宋體","黑體","楷體"};
String list2[]={"常規(guī)","斜體","粗體","粗斜體"};
String list3[]={"8","9","10","11","12","14","16","18","20","22","24","26","28","36","48","72"};
JLabel jLabel1 = new JLabel();
XYLayout xYLayout1 = new XYLayout();
JTextField jTextField1 = new JTextField();
JList jList1 = new JList(list1);
JLabel jLabel2 = new JLabel();
JTextField jTextField2 = new JTextField();
JList jList2 = new JList(list2);
JLabel jLabel3 = new JLabel();
JTextField jTextField3 = new JTextField();
JList jList3 = new JList(list3);
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JPanel jPanel1 = new JPanel();
Border border1 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
Color.white, new Color(165, 163, 151));
Border border2 = new TitledBorder(border1, "示例");
XYLayout xYLayout2 = new XYLayout();
JLabel jLabel4 = new JLabel();
Border border3 = BorderFactory.createBevelBorder(BevelBorder.RAISED,
Color.white, Color.white, new Color(115, 114, 105),
new Color(165, 163, 151));
Border border13 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
Color.white, new Color(165, 163, 151));
Border border14 = BorderFactory.createLineBorder(Color.LIGHT_GRAY,1);
Border border15 = new TitledBorder(border14, "示例");
public format() {
try {
jbInit();
this.setTitle("字體");
} catch (Exception ex) {
ex.printStackTrace();
}
}
public format(JNotePadUI note) {
try {
this.note=note;
Font fo=note.jTextArea.getFont();
style=fo.getFontName();
font=fo.getStyle();
getfontname(font);
size=fo.getSize();
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void getfontname(int n){
switch(n){
case Font.BOLD:fontname="粗體";break;
case Font.ITALIC:fontname="斜體";break;
case Font.BOLD+Font.ITALIC:fontname="粗斜體";break;
case Font.PLAIN:fontname="常規(guī)";break;
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(xYLayout1);
jLabel1.setText("字體(F):");
jLabel2.setText("字形(Y):");
jTextField2.setText(fontname);
jLabel3.setText("大小(s):");
jTextField3.setText(new Integer(size).toString());
jButton1.setText("確定");
jButton1.addActionListener(new format_jButton1_actionAdapter(this));
jButton2.setText("取消");
jButton2.addActionListener(new format_jButton2_actionAdapter(this));
jPanel1.setBorder(border15);
jPanel1.setLayout(xYLayout2);
jLabel4.setBorder(border13);
jLabel4.setToolTipText("");
jLabel4.setDisplayedMnemonic('0');
jLabel4.setHorizontalAlignment(SwingConstants.CENTER);
jLabel4.setText("王利華");
jList2.addListSelectionListener(new format_jList2_listSelectionAdapter(this));
jList1.addListSelectionListener(new format_jList1_listSelectionAdapter(this));
jList3.addListSelectionListener(new format_jList3_listSelectionAdapter(this));
jButton1.addActionListener(new format_jButton1_actionAdapter(this));
this.getContentPane().add(jLabel1, new XYConstraints(20, 12, -1, -1));
this.getContentPane().add(jButton2, new XYConstraints(318, 59, 68, 20));
this.getContentPane().add(jButton1, new XYConstraints(318, 32, 66, 20));
this.getContentPane().add(jTextField3,
new XYConstraints(245, 30, 51, 15));
this.getContentPane().add(new JScrollPane(jList3), new XYConstraints(246, 47, 49, 111));
this.getContentPane().add(jLabel3, new XYConstraints(244, 12, 45, -1));
this.getContentPane().add(jTextField2,
new XYConstraints(137, 30, 94, 15));
this.getContentPane().add(new JScrollPane(jList1), new XYConstraints(20, 46, 103, 112));
this.getContentPane().add(jList2, new XYConstraints(137, 46, 94, 112));
this.getContentPane().add(jLabel2, new XYConstraints(139, 14, 47, 13));
this.getContentPane().add(jTextField1,
new XYConstraints(20, 30, 104, 15));
this.getContentPane().add(jPanel1, new XYConstraints(150, 164, 144, 80));
jPanel1.add(jLabel4, new XYConstraints(10, 0, 113, 41));
jTextField1.setText(style);
}
public void jList2_valueChanged(ListSelectionEvent e) {
String s=(String)jList2.getSelectedValue();
jTextField2.setText(s);
setfont(s);
jLabel4.setFont(new Font(style,font,size));
}
public void setfont(String s)
{
if(s.equals("常規(guī)"))
font=plainfont;
else if(s.equals("粗體"))
font=Font.BOLD;
else if(s.equals("斜體"))
font=Font.ITALIC;
else font=bifont;
}
public void jList1_valueChanged(ListSelectionEvent e) {
style=(String)jList1.getSelectedValue();
jTextField1.setText(style);
jLabel4.setFont(new Font(style,font,size));
}
public void jList3_valueChanged(ListSelectionEvent e) {
String s=(String)jList3.getSelectedValue();
jTextField3.setText(s);
size=Integer.parseInt(s);
jLabel4.setFont(new Font(style,font,size));
}
public void jButton2_actionPerformed(ActionEvent e) {
this.setVisible(false);
}
public void jButton1_actionPerformed(ActionEvent e) {
note.jTextArea.setFont(new Font(style,font,size));
this.setVisible(false);
}
}
class format_jButton2_actionAdapter implements ActionListener {
private format adaptee;
format_jButton2_actionAdapter(format adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class format_jButton1_actionAdapter implements ActionListener {
private format adaptee;
format_jButton1_actionAdapter(format adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class format_jList2_listSelectionAdapter implements ListSelectionListener {
private format adaptee;
format_jList2_listSelectionAdapter(format adaptee) {
this.adaptee = adaptee;
}
public void valueChanged(ListSelectionEvent e) {
adaptee.jList2_valueChanged(e);
}
}
class format_jList1_listSelectionAdapter implements ListSelectionListener {
private format adaptee;
format_jList1_listSelectionAdapter(format adaptee) {
this.adaptee = adaptee;
}
public void valueChanged(ListSelectionEvent e) {
adaptee.jList1_valueChanged(e);
}
}
class format_jList3_listSelectionAdapter implements ListSelectionListener {
private format adaptee;
format_jList3_listSelectionAdapter(format adaptee) {
this.adaptee = adaptee;
}
public void valueChanged(ListSelectionEvent e) {
adaptee.jList3_valueChanged(e);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -