a.arefi
یک شنبه 26 آبان 1392, 19:30 عصر
دوستان کسی می تونه کمک منه چرا این برنامه اجرا می شه ولی کار نمی کنه
در واقع زیر این کلاس CheckBoxHandler قرمز که نباید اینطور باشه این کد کتاب دایتل است.
این کلاس اولیه
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JCheckBox;
public class CheckBoxFrame extends JFrame
{
private JTextField textFiled;
private JCheckBox boldJCheckBox;
private JCheckBox italicJCheckBox;
public CheckBoxFrame()
{
super("text bold & italic");
setLayout(new FlowLayout());
textFiled = new JTextField("watch the font style change",20);
textFiled.setFont(new Font("Serif", Font.PLAIN, 14));
add(textFiled);
boldJCheckBox = new JCheckBox("Bold");
italicJCheckBox = new JCheckBox("Italic");
add(boldJCheckBox);
add(italicJCheckBox);
CheckBoxHandler handeler = new CheckBoxHandler();
boldJCheckBox.addItemListener(handeler);
italicJCheckBox.addItemListener(handeler);
}
private class CheckBoxHandler implements ItemListener
{
public void ItemStateChange(ItemEvent event)
{
Font font = null;
if (boldJCheckBox.isSelected() && italicJCheckBox.isSelected())
font = new Font("Serif", Font.BOLD + Font.ITALIC, 14);
else if (boldJCheckBox.isSelected())
font = new Font("Serif", Font.BOLD,14);
else if (italicJCheckBox.isSelected())
font = new Font("Serif",Font.ITALIC, 14);
else font = new Font("Serif",Font.PLAIN,14);
textFiled.setFont(font);
}
}
}
[/LTR][/LTR][/LEFT]
اینم کلاس اجرا
import javax.swing.JFrame;
public class mainClass {
public static void main(String[] args )
{
CheckBoxFrame chechBoxFrame = new CheckBoxFrame();
chechBoxFrame.setDefaultCloseOperation(JFrame.EXIT _ON_CLOSE);
chechBoxFrame.setSize(275,100);
chechBoxFrame.setVisible(true);
}
}
در واقع زیر این کلاس CheckBoxHandler قرمز که نباید اینطور باشه این کد کتاب دایتل است.
این کلاس اولیه
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JCheckBox;
public class CheckBoxFrame extends JFrame
{
private JTextField textFiled;
private JCheckBox boldJCheckBox;
private JCheckBox italicJCheckBox;
public CheckBoxFrame()
{
super("text bold & italic");
setLayout(new FlowLayout());
textFiled = new JTextField("watch the font style change",20);
textFiled.setFont(new Font("Serif", Font.PLAIN, 14));
add(textFiled);
boldJCheckBox = new JCheckBox("Bold");
italicJCheckBox = new JCheckBox("Italic");
add(boldJCheckBox);
add(italicJCheckBox);
CheckBoxHandler handeler = new CheckBoxHandler();
boldJCheckBox.addItemListener(handeler);
italicJCheckBox.addItemListener(handeler);
}
private class CheckBoxHandler implements ItemListener
{
public void ItemStateChange(ItemEvent event)
{
Font font = null;
if (boldJCheckBox.isSelected() && italicJCheckBox.isSelected())
font = new Font("Serif", Font.BOLD + Font.ITALIC, 14);
else if (boldJCheckBox.isSelected())
font = new Font("Serif", Font.BOLD,14);
else if (italicJCheckBox.isSelected())
font = new Font("Serif",Font.ITALIC, 14);
else font = new Font("Serif",Font.PLAIN,14);
textFiled.setFont(font);
}
}
}
[/LTR][/LTR][/LEFT]
اینم کلاس اجرا
import javax.swing.JFrame;
public class mainClass {
public static void main(String[] args )
{
CheckBoxFrame chechBoxFrame = new CheckBoxFrame();
chechBoxFrame.setDefaultCloseOperation(JFrame.EXIT _ON_CLOSE);
chechBoxFrame.setSize(275,100);
chechBoxFrame.setVisible(true);
}
}