1)怎样设置JLABLE的摆放位置?
2)我的程序如下:为什么运行时我改变下拉菜单1的选项,字体却没有变化呢
import java.awt.*;
import java.applet.*;
import javax.swing.*;
import java.awt.event.*;public class ChangeFC extends JApplet implements ItemListener,ActionListener{
private String item1[]={"Serif","Dialog","Monospaced"};
private String item2[]={"red","green","blue"};
private Color color1[]={Color.red,Color.green,Color.blue};
private JComboBox combo1=new JComboBox(item1);
private JComboBox combo2=new JComboBox(item2);
JLabel label1,label2,label3;
Color color=Color.red;
Container c;
private Font font=new Font("Serif",Font.BOLD,18);
public void init()
{
c=getContentPane();
c.setLayout(new FlowLayout(FlowLayout.CENTER));
combo1.addItemListener(this);
combo2.addItemListener(this);
label1=new JLabel("字体");
label2=new JLabel("颜色");
label3=new JLabel("Hello World!");
c.add(label1);
c.add(combo1);
c.add(label2);
c.add(combo2);
label3.setFont(font);
label3.setForeground(color);
label3.setBounds(200,400,100,100);
c.add(label3);
setSize(400,800);
}
public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub
if(e.getSource()=="combo1")
label3.setFont(new Font(item1[combo1.getSelectedIndex()],Font.BOLD,18));
else
label3.setForeground(color1[combo2.getSelectedIndex()]);
c.validate();
}public void actionPerformed(ActionEvent e) {
}
}
2)我的程序如下:为什么运行时我改变下拉菜单1的选项,字体却没有变化呢
import java.awt.*;
import java.applet.*;
import javax.swing.*;
import java.awt.event.*;public class ChangeFC extends JApplet implements ItemListener,ActionListener{
private String item1[]={"Serif","Dialog","Monospaced"};
private String item2[]={"red","green","blue"};
private Color color1[]={Color.red,Color.green,Color.blue};
private JComboBox combo1=new JComboBox(item1);
private JComboBox combo2=new JComboBox(item2);
JLabel label1,label2,label3;
Color color=Color.red;
Container c;
private Font font=new Font("Serif",Font.BOLD,18);
public void init()
{
c=getContentPane();
c.setLayout(new FlowLayout(FlowLayout.CENTER));
combo1.addItemListener(this);
combo2.addItemListener(this);
label1=new JLabel("字体");
label2=new JLabel("颜色");
label3=new JLabel("Hello World!");
c.add(label1);
c.add(combo1);
c.add(label2);
c.add(combo2);
label3.setFont(font);
label3.setForeground(color);
label3.setBounds(200,400,100,100);
c.add(label3);
setSize(400,800);
}
public void itemStateChanged(ItemEvent e) {
// TODO Auto-generated method stub
if(e.getSource()=="combo1")
label3.setFont(new Font(item1[combo1.getSelectedIndex()],Font.BOLD,18));
else
label3.setForeground(color1[combo2.getSelectedIndex()]);
c.validate();
}public void actionPerformed(ActionEvent e) {
}
}
combo2.addItemListener(this);
这两句没起作用