下面的程序一运行就有异常,请问是为什么,哪里出了问题?请高手指点
package 记事本;
import java.awt.BorderLayout;
import java.awt.Frame;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.*;
import 记事本.Frame1;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.*;
public class DialogFont extends JDialog {
JPanel panel1 = new JPanel();
JLabel lblFont = new JLabel();
JLabel lblType = new JLabel();
JLabel lblSize = new JLabel();
static Frame1 f;
JTextField txtFont = new JTextField();
JTextField txtType = new JTextField();
JTextField txtSize = new JTextField();
JComboBox cboFont = new JComboBox();
JComboBox cboType = new JComboBox();
JComboBox cboSize = new JComboBox();
JButton btnDecide = new JButton();
JButton btnCancel = new JButton();
JPanel jPanel1 = new JPanel();
JTextField txtExample = new JTextField();
JLabel lblExample = new JLabel();
int i,j;
Font font;
//得到系统中的所有字体,将返回值放到fonts字符串数组中
String[] fonts=GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
int[] size={8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
public DialogFont(Frame owner, String title, boolean modal) {
super(owner, title, modal);
try {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jbInit();
pack();
} catch (Exception exception) {
exception.printStackTrace();
}
}
public DialogFont() {
this(new Frame(), "DialogFont", false);
}
private void jbInit() throws Exception {
panel1.setLayout(null);
this.setResizable(false);
this.setTitle("字体");
lblFont.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
lblFont.setText("字体");
lblFont.setBounds(new Rectangle(9, 12, 54, 25));
lblType.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
lblType.setText("字形");
lblType.setBounds(new Rectangle(138, 12, 54, 25));
lblSize.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
lblSize.setText("大小");
lblSize.setBounds(new Rectangle(261, 12, 54, 25));
txtFont.setText("");
txtFont.setBounds(new Rectangle(9, 37, 88, 21));
txtType.setText("");
txtType.setBounds(new Rectangle(138, 37, 88, 21));
txtSize.setText("");
txtSize.setBounds(new Rectangle(261, 37, 88, 21));
cboFont.setBounds(new Rectangle(9, 72, 88, 21));
cboType.setBounds(new Rectangle(138, 72, 88, 21));
cboSize.setBounds(new Rectangle(261, 72, 88, 21));
btnDecide.setBounds(new Rectangle(281, 113, 62, 29));
btnDecide.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
btnDecide.setText("确定");
btnCancel.setBounds(new Rectangle(281, 157, 62, 29));
btnCancel.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
btnCancel.setText("取消");
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setBounds(new Rectangle(82, 114, 165, 77));
jPanel1.setLayout(null);
txtExample.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
txtExample.setText("我是个例子");
txtExample.setHorizontalAlignment(SwingConstants.CENTER);
txtExample.setBounds(new Rectangle(14, 8, 137, 61));
lblExample.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
lblExample.setText("示例");
lblExample.setBounds(new Rectangle(27, 124, 39, 43));
panel1.add(lblFont);
panel1.add(lblType);
panel1.add(txtType);
panel1.add(txtFont);
panel1.add(cboFont);
panel1.add(cboType);
panel1.add(txtSize);
panel1.add(lblSize);
panel1.add(cboSize);
panel1.add(jPanel1);
jPanel1.add(txtExample);
panel1.add(btnDecide);
panel1.add(btnCancel);
panel1.add(lblExample);
for(i=0;i<fonts.length;i++){
cboFont.addItem(fonts[i]);//将fonts数组中的所有字体添加到cboFont中
}
cboType.addItem("常规"); //设置字形选项
cboType.addItem("斜体");
cboType.addItem("粗体");
cboType.addItem("粗斜体");
for(j=0;j<size.length;j++){ //设置字号选项
String b = Integer.toString(size[j]);
cboSize.addItem(b);
}
this.getContentPane().add(panel1, java.awt.BorderLayout.CENTER);
if(cboType.getSelectedIndex()==0){
txtExample.setFont(new Font(fonts[i],Font.PLAIN,size[j]));
}
}
}
[此贴子已经被作者于2007-7-31 15:51:03编辑过]