当前位置: 技术问答>java相关
使用组合框JComboBox出现的问题
来源: 互联网 发布时间:2015-09-26
本文导语: 在JDK1.4下面,一个小程序有两个窗体,一个是主窗体,一个是对话框,这个对话框 看下面的源程序: //主窗体 //Test.java import java.awt.event.*; import javax.swing.*; import java.awt.*; public class Test extends JFrame { private...
在JDK1.4下面,一个小程序有两个窗体,一个是主窗体,一个是对话框,这个对话框
看下面的源程序:
//主窗体
//Test.java
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class Test extends JFrame {
private TestDialog tdialog;
private int i;
public Test() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
JButton button = new JButton("Test");
Container contpane = getContentPane();
contpane.add(button,BorderLayout.NORTH);
tdialog = new TestDialog();
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
tdialog.show();
}
});
i=10;
}
public static void main(String[] args) {
Test frame = new Test();
frame.setSize(500, 400);
frame.setTitle("Test");
frame.setVisible(true);
}
public int GetNum()
{
return i;
}
}
//对话框
//TestDialog.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestDialog extends javax.swing.JDialog
{
private JButton b;
private JComboBox combobox;
public TestDialog()
{
this(null, "", true);
}
public TestDialog(Frame frame, String title, boolean modal)
{
super(frame, title, modal);
jdInit();
}
private void jdInit()
{
b = new JButton ("Test");
combobox = new JComboBox();
for(int i=0 ;i
看下面的源程序:
//主窗体
//Test.java
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class Test extends JFrame {
private TestDialog tdialog;
private int i;
public Test() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});
JButton button = new JButton("Test");
Container contpane = getContentPane();
contpane.add(button,BorderLayout.NORTH);
tdialog = new TestDialog();
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae)
{
tdialog.show();
}
});
i=10;
}
public static void main(String[] args) {
Test frame = new Test();
frame.setSize(500, 400);
frame.setTitle("Test");
frame.setVisible(true);
}
public int GetNum()
{
return i;
}
}
//对话框
//TestDialog.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestDialog extends javax.swing.JDialog
{
private JButton b;
private JComboBox combobox;
public TestDialog()
{
this(null, "", true);
}
public TestDialog(Frame frame, String title, boolean modal)
{
super(frame, title, modal);
jdInit();
}
private void jdInit()
{
b = new JButton ("Test");
combobox = new JComboBox();
for(int i=0 ;i