2012年6月1日 星期五

Java Basic(65)-The Final Check Box Program


Continue Java Basic(64)



private class HandlerClass implements ItemListener{
public void itemStateChanged(ItemEvent event){
Font font = null;
if(boldbox.isSelected() && italicbox.isSelected())
font = new Font("Serif", Font.BOLD + Font.ITALIC, 14);
else if(boldbox.isSelected())
font = new Font("Serif", Font.BOLD, 14);
else if(italicbox.isSelected())
font = new Font("Serif", Font.ITALIC, 14);
else
font = new Font("Serif", Font.PLAIN, 14);
tf.setFont(font);
}
}

The apples.java is same:
import javax.swing.JFrame;

class apples{
public static void main(String[] args){
Gui go = new Gui();
go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
go.setSize(400, 200);
go.setVisible(true);
}
}


然後運行,你可以checkbox,並改變字體為粗體和斜體







沒有留言:

張貼留言