编写程序:建立一个班级下拉式列表,列表项中有101班、102班、103班、104班和105班
发布网友
发布时间:2022-05-04 01:28
我来回答
共2个回答
热心网友
时间:2023-10-21 20:32
importjavax.swing.*;
import java.awt.*;
importjava.awt.event.*;
public class Testextends JApplet implements ItemListener
{ Container ctp=getContentPane();
JLabel lb1=new JLabel("班级:");
String name[]={"101","102","103","104"};
JComboBox cbx=new JComboBox();
JButton bt=new JButton();
Font f=newFont("Arial",Font.PLAIN,24);
Color c=Color.red;
public void init() {
ctp.setLayout(new FlowLayout());
for(int j=0;j<name.length;j++)
cbx.addItem(name[j]);
ctp.add(lb1);
ctp.add(cbx);
cbx.addItemListener(this);
bt.setForeground(c);
ctp.add(bt);
}
public void itemStateChanged(ItemEvent e)
{int i=0;
String str=(String)e.getItem();
for(int c=0;c<name.length;c++)
if(str==name[c])
i=cbx.getSelectedIndex();
bt.setFont(f);
bt.setText(name[i]);
}
}
热心网友
时间:2023-10-21 20:32
c#得话用droplist
热心网友
时间:2023-10-21 20:32
importjavax.swing.*;
import java.awt.*;
importjava.awt.event.*;
public class Testextends JApplet implements ItemListener
{ Container ctp=getContentPane();
JLabel lb1=new JLabel("班级:");
String name[]={"101","102","103","104"};
JComboBox cbx=new JComboBox();
JButton bt=new JButton();
Font f=newFont("Arial",Font.PLAIN,24);
Color c=Color.red;
public void init() {
ctp.setLayout(new FlowLayout());
for(int j=0;j<name.length;j++)
cbx.addItem(name[j]);
ctp.add(lb1);
ctp.add(cbx);
cbx.addItemListener(this);
bt.setForeground(c);
ctp.add(bt);
}
public void itemStateChanged(ItemEvent e)
{int i=0;
String str=(String)e.getItem();
for(int c=0;c<name.length;c++)
if(str==name[c])
i=cbx.getSelectedIndex();
bt.setFont(f);
bt.setText(name[i]);
}
}
热心网友
时间:2023-10-21 20:32
c#得话用droplist
热心网友
时间:2023-10-21 20:32
importjavax.swing.*;
import java.awt.*;
importjava.awt.event.*;
public class Testextends JApplet implements ItemListener
{ Container ctp=getContentPane();
JLabel lb1=new JLabel("班级:");
String name[]={"101","102","103","104"};
JComboBox cbx=new JComboBox();
JButton bt=new JButton();
Font f=newFont("Arial",Font.PLAIN,24);
Color c=Color.red;
public void init() {
ctp.setLayout(new FlowLayout());
for(int j=0;j<name.length;j++)
cbx.addItem(name[j]);
ctp.add(lb1);
ctp.add(cbx);
cbx.addItemListener(this);
bt.setForeground(c);
ctp.add(bt);
}
public void itemStateChanged(ItemEvent e)
{int i=0;
String str=(String)e.getItem();
for(int c=0;c<name.length;c++)
if(str==name[c])
i=cbx.getSelectedIndex();
bt.setFont(f);
bt.setText(name[i]);
}
}
热心网友
时间:2023-10-21 20:32
c#得话用droplist