哪位大虾给我讲讲Java做的记事本的背景色怎么设计实现

2022-03-24 科技 78阅读
这是设置字体的代码。窗口的设计代码我省略了,这些是事件处理
//字体窗口中JTextFiled获得选中的字符
classxianshi1implementsActionListener{
publicvoidactionPerformed(ActionEvente){
fonttext.setText((String)((JComboBox)e.getSource())
.getSelectedItem());
}

}

classxianshi2implementsActionListener{
publicvoidactionPerformed(ActionEvente){
styletext.setText((String)((JComboBox)e.getSource())
.getSelectedItem());
}
}

classxianshi3implementsActionListener{
publicvoidactionPerformed(ActionEvente){
sizetext.setText((String)((JComboBox)e.getSource())
.getSelectedItem());
}

}

classquedingimplementsActionListener{
publicvoidactionPerformed(ActionEvente){
if(e.getSource()==ok){
flg3=1;
ss();
fontdialog.dispose();
}
if(e.getSource()==cancel){
fontdialog.dispose();
}
}
}

//字体事件方法
publicvoidss(){
Stringziti,zixing,zihao;
//为字形定义一个变量
intstyle=Font.PLAIN;
//得到JComboBox中字符
ziti=(String)combo[0].getSelectedItem();
zixing=(String)combo[1].getSelectedItem();
zihao=(String)combo[2].getSelectedItem();

if(zixing.equals("斜体")){
style=Font.ITALIC;
}
if(zixing.equals("粗体")){
style=Font.BOLD;
}
if(zixing.equals("粗斜体")){
style=Font.ITALIC;
style=Font.BOLD;
}
sample.setFont(newFont(ziti,style,Integer.parseInt(zihao)));//应用修改后的字体
if(flg3==1){
text.setFont(newFont(ziti,style,Integer.parseInt(zihao)));
flg3=0;
}
}

}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com