package countrymessage;import java.awt.BorderLayout;
import java.awt.Dimension;import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.*;
import javax.swing.JComboBox;
import javax.swing.JTextArea;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class CountryMessageFrame extends JFrame {
JPanel contentPane;
JLabel jLabel1 = new JLabel();
JComboBox jComboBox1 = new JComboBox();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextArea jTextArea1 = new JTextArea();
JButton jButton1 = new JButton();
JLabel jLabel4 = new JLabel();
public CountryMessageFrame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
} /**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(400, 400));
setTitle("国家信息");
jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jLabel1.setText("国家(地区)名:");
jLabel1.setBounds(new Rectangle(43, 40, 108, 40));
jComboBox1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jComboBox1.setBounds(new Rectangle(160, 51, 123, 33));
jComboBox1.addItem("");
jComboBox1.addItem("中国");
jComboBox1.addItem("日本");
jComboBox1.addItem("美国");
jComboBox1.addItem("埃及");
jComboBox1.addItem("韩国");
jLabel2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jLabel2.setText("国旗");
jLabel2.setBounds(new Rectangle(43, 115, 75, 29));
jLabel3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jLabel3.setText("信息");
jLabel3.setBounds(new Rectangle(207, 115, 75, 29));
jTextArea1.setBounds(new Rectangle(207, 150, 145, 90));
jButton1.setBounds(new Rectangle(156, 256, 87, 35));
jButton1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jButton1.setText("显示");
jButton1.addActionListener(new
CountryMessageFrame_jButton1_actionAdapter(this));
jLabel4.setBounds(new Rectangle(15, 145, 182, 101));
contentPane.add(jLabel1);
contentPane.add(jComboBox1);
contentPane.add(jLabel2);
contentPane.add(jLabel3);
contentPane.add(jTextArea1);
contentPane.add(jButton1);
contentPane.add(jLabel4);
} public void jButton1_actionPerformed(ActionEvent e) {
String country=jComboBox1.getToolTipText();
if(country!=null){
if(country=="中国"){
jTextArea1.setText("中国是一个富饶的国家");
jLabel4.setIcon(new ImageIcon("D:\\study\\java\\10\\work\\p232\\CountryMessage\\pic\\China.jpg"));
}
}
}
}
class CountryMessageFrame_jButton1_actionAdapter implements ActionListener {
private CountryMessageFrame adaptee;
CountryMessageFrame_jButton1_actionAdapter(CountryMessageFrame adaptee) {
this.adaptee = adaptee;
} public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
import java.awt.Dimension;import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.*;
import javax.swing.JComboBox;
import javax.swing.JTextArea;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class CountryMessageFrame extends JFrame {
JPanel contentPane;
JLabel jLabel1 = new JLabel();
JComboBox jComboBox1 = new JComboBox();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextArea jTextArea1 = new JTextArea();
JButton jButton1 = new JButton();
JLabel jLabel4 = new JLabel();
public CountryMessageFrame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
} /**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(null);
setSize(new Dimension(400, 400));
setTitle("国家信息");
jLabel1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jLabel1.setText("国家(地区)名:");
jLabel1.setBounds(new Rectangle(43, 40, 108, 40));
jComboBox1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jComboBox1.setBounds(new Rectangle(160, 51, 123, 33));
jComboBox1.addItem("");
jComboBox1.addItem("中国");
jComboBox1.addItem("日本");
jComboBox1.addItem("美国");
jComboBox1.addItem("埃及");
jComboBox1.addItem("韩国");
jLabel2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jLabel2.setText("国旗");
jLabel2.setBounds(new Rectangle(43, 115, 75, 29));
jLabel3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jLabel3.setText("信息");
jLabel3.setBounds(new Rectangle(207, 115, 75, 29));
jTextArea1.setBounds(new Rectangle(207, 150, 145, 90));
jButton1.setBounds(new Rectangle(156, 256, 87, 35));
jButton1.setFont(new java.awt.Font("Dialog", Font.PLAIN, 16));
jButton1.setText("显示");
jButton1.addActionListener(new
CountryMessageFrame_jButton1_actionAdapter(this));
jLabel4.setBounds(new Rectangle(15, 145, 182, 101));
contentPane.add(jLabel1);
contentPane.add(jComboBox1);
contentPane.add(jLabel2);
contentPane.add(jLabel3);
contentPane.add(jTextArea1);
contentPane.add(jButton1);
contentPane.add(jLabel4);
} public void jButton1_actionPerformed(ActionEvent e) {
String country=jComboBox1.getToolTipText();
if(country!=null){
if(country=="中国"){
jTextArea1.setText("中国是一个富饶的国家");
jLabel4.setIcon(new ImageIcon("D:\\study\\java\\10\\work\\p232\\CountryMessage\\pic\\China.jpg"));
}
}
}
}
class CountryMessageFrame_jButton1_actionAdapter implements ActionListener {
private CountryMessageFrame adaptee;
CountryMessageFrame_jButton1_actionAdapter(CountryMessageFrame adaptee) {
this.adaptee = adaptee;
} public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
你的事件监听不对。自己找找api上点击的监听是怎样的。