【发布时间】:2018-08-04 11:58:24
【问题描述】:
我正在用 java 创建一个记事本。我需要帮助,因为我们知道记事本中有一个字体选择器选项。我也想在记事本中添加该选项,但 FontChooser 类也不可用。
因此,我正在创建自己的课程。 为此,我正在使用包含各种 listItems(如 PLAIN、BOLD、ITALIC)的 listItems,然后将此值设置为 textField,就像在记事本中发生的那样。
我的问题是 java 中有 setFont() 方法,我就是这样使用它的
public void itemStateChanged(ItemEvent e)
{
List temp=(List)e.getSource();
if(temp==list1)
{
tft.setText(list1.getSelectedItem());
tft6.setFont(new Font(list1.getSelectedItem(),,Integer.parseInt(tft4.getText())));
}
else if(temp==list2)
{
tft2.setText(list2.getSelectedItem());
if(tft2.getText().equalsIgnoreCase("BOLD"))
{
tft6.setFont(new Font(list1.getSelectedItem(),Font.BOLD,Integer.parseInt(tft4.getText())));
}
else if(tft2.getText().equalsIgnoreCase("ITALIC"))
{
tft6.setFont(new Font(list1.getSelectedItem(),Font.ITALIC,Integer.parseInt(tft4.getText()))); }
else if(tft2.getText().equalsIgnoreCase("PLAIN"))
{
tft6.setFont(new Font(list1.getSelectedItem(),Font.PLAIN,Integer.parseInt(tft4.getText())));
}
}
else if(temp==list3)
{
tft4.setText(list3.getSelectedItem());
tft6.setFont(new Font(list1.getSelectedItem(),Font.BOLD,Integer.parseInt(tft4.getText())));
}
}
看temp==list2
我将不得不一次又一次地检查tft2.eqaulsIgnoreCase()
我在setFont(list1.getSelectedItem(),list2.getSelectedItem(),list3.getSelectedItem()) 中可以做什么我不能在list2.getSelectedItem() 因为 Font.BOLD\PLAIN\ITALIC
我能做什么???
【问题讨论】:
-
仔细格式化你的源代码
-
您的问题到底是什么?我什至读过你的 cmets,但我仍然不明白你想问什么。