packageS12;importjava.awt.*;importjavax.swing.*;importjava.awt.event.*;classhhextendsJFrameimplementsItemListener{JFramejfr;JComboBoxcom;JPanelpan;JButtonbut;Stringsz[]={...
package S12;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class hh extends JFrame implements ItemListener {
JFrame jfr;
JComboBox com;
JPanel pan;
JButton but;
String sz[] = { "10,14,18" };
hh(String s) {
super(s);
setSize(500, 800);
setLocationRelativeTo(null);
pan = new JPanel();
setContentPane(pan);
but = new JButton("按钮");
com = new JComboBox();
for (int i = 0; i < 3; i++) {
com.addItem(sz[i]);
}
com.addItemListener(this);
pan.add(but);
pan.add(com);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
@Override
public void itemStateChanged(ItemEvent e) {
if (com.getSelectedItem().toString() == "10")
but.setFont(new Font(null, Font.PLAIN, 10));
if (com.getSelectedItem().toString() == "14")
but.setFont(new Font(null, Font.PLAIN, 14));
if (com.getSelectedItem().toString() == "18")
but.setFont(new Font(null, Font.PLAIN, 18));
}
}
public class T5 {
public static void main(String[] args) {
hh st = new hh("作业5");
}
}
Exceliption 旁边没有报错,但是运行的时候总是报错,有大神可以帮忙看下吗? 谢谢!!!
展开