import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class TtpDemo extends JFrame
{
TtpDemo()
{
super("卡片选项页面示例");
setSize(300,200);
setVisible(true);
JTabbedPane jtp=new JTabbedPane();
ImageIcon icon1=new ImageIcon("c1.gif");
ImageIcon icon2=new ImageIcon("c2.gif");
ImageIcon icon3=new ImageIcon("c3.gif");
jtp.addTab("城市",icon1,new CitiesPanel(),"城市名称");
jtp.addTab("文学",icon2,new BookPanel(),"文学书目");
jtp.addTab("网站",icon3,new NetPanel(),"精选网址");
getContentPane().add(jtp);
validate();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{System.exit(0);}
});
}
}
class CitiesPanel extends JPanel implements ActionListener
{
CitiesPanel()
{
JButton b1=new JButton("北京");
JButton b2=new JButton("上海");
JButton b3=new JButton("深圳");
JButton b4=new JButton("厦门");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
add(b1);add(b2);add(b3);add(b4);
}
public void actonPerformed(ActionEvent e)
{
if(e.getSource==b1)
{
String URL="\"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE\"http://www.163.com";
Process pp=Runtime.getRuntime().exec(URL);
}
if(e.getSource==b2)
{
String URL="\"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE\"http://www.sina.com";
Process pp=Runtime.getRuntime().exec(URL);
}
if(e.getSource==b3)
{
String URL="\"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE\"http://www.126.com";
Process pp=Runtime.getRuntime().exec(URL);
}
if(e.getSource==b4)
{
String URL="\"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE\"http://www.sohu.com";
Process pp=Runtime.getRuntime().exec(URL);
}
}
class BookPanel extends JPanel
{
BookPanel()
{
JCheckBox cb1=new JCheckBox("西游记");
JCheckBox cb2=new JCheckBox("三国演义");
JCheckBox cb3=new JCheckBox("红楼梦");
add(cb1);add(cb2);add(cb3);
}
}
class NetPanel extends JPanel
{
NetPanel()
{
JComboBox jcb=new JComboBox();
jcb.addItem("思维论坛");
jcb.addItem("百度摸索");
jcb.addItem("爱好者");
add(jcb);
}
}
public class Example5_7
{
public static void main(String args[])
{new TtpDemo();}
}
请问错在哪里呢?
编译时出现:进行语法解释时已到达文件结尾 的错误.
解决方案 »
- 正则表达式替换字符串
- 请教一个问题 如何1~9这九个数填充到一个9*9的数组 并输出所有可能
- java 传引用????急急急
- 有在四川读北大青鸟的朋友吗。希望指导下
- 怎样可以响应“新建”子菜单
- 请教一个问题!
- 创建String对象的问题
- 一个ArrayList里的元素全部是Byte对象.怎么才能把这个ArrayList转换成一个byte[](不是Byte[])
- 怎样看一个可执行的程序的代码?(用java写的)
- 兄弟们推荐一本学习jbuilder的书,最初级的!就是一步一个图的那种!
- 字符串数字 转换为 字节型
- com.enterprisedt.net.ftp.FTPClient中restart
第二个问题,e.getSource应该是e.getSource()
第三个问题,b1,b2,b3,b4应该定义为类的变量,而不是定义的构造函数里。
第四个问题,CitiesPanel还应该实现public void actionPerformed(ActionEvent arg0)方法。
import java.awt.event.*;import javax.swing.*;
class TtpDemo extends JFrame
{
TtpDemo()
{
super("卡片选项页面示例");
setSize(300,200);
setVisible(true);
JTabbedPane jtp=new JTabbedPane();
ImageIcon icon1=new ImageIcon("c1.gif");
ImageIcon icon2=new ImageIcon("c2.gif");
ImageIcon icon3=new ImageIcon("c3.gif");
jtp.addTab("城市",icon1,new CitiesPanel(),"城市名称");
jtp.addTab("文学",icon2,new BookPanel(),"文学书目");
jtp.addTab("网站",icon3,new NetPanel(),"精选网址");
getContentPane().add(jtp);
validate();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{System.exit(0);}
});
}
}
class CitiesPanel extends JPanel implements ActionListener
{
JButton b1=new JButton("北京");
JButton b2=new JButton("上海");
JButton b3=new JButton("深圳");
JButton b4=new JButton("厦门"); CitiesPanel()
{
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
add(b1);add(b2);add(b3);add(b4);
}
public void actonPerformed(ActionEvent e)
{
try {
if (e.getSource() == b1) {
String URL = "\"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE\"http://www.163.com";
Process pp = Runtime.getRuntime().exec(URL);
}
if (e.getSource() == b2) {
String URL = "\"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE\"http://www.sina.com";
Process pp = Runtime.getRuntime().exec(URL);
}
if (e.getSource() == b3) {
String URL = "\"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE\"http://www.126.com";
Process pp = Runtime.getRuntime().exec(URL);
}
if (e.getSource() == b4) {
String URL = "\"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE\"http://www.sohu.com";
Process pp = Runtime.getRuntime().exec(URL);
}
}catch(Exception ex){
}
}
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
}
class BookPanel extends JPanel
{
BookPanel()
{
JCheckBox cb1=new JCheckBox("西游记");
JCheckBox cb2=new JCheckBox("三国演义");
JCheckBox cb3=new JCheckBox("红楼梦");
add(cb1);add(cb2);add(cb3);
}
}
class NetPanel extends JPanel
{
NetPanel()
{
JComboBox jcb=new JComboBox();
jcb.addItem("思维论坛");
jcb.addItem("百度摸索");
jcb.addItem("爱好者");
add(jcb);
}
}
public class Example5_7
{
public static void main(String args[])
{new TtpDemo();}
}
能不能解释一下:CitiesPanel还应该实现public void actionPerformed(ActionEvent arg0)方法呢?
我这里可以打开了啊。你把:
}catch(Exception ex){
}
改成
}catch(Exception ex){
ex.printStackTrace();
}
看看运行的时候抛了什么异常。
import java.awt.event.*;import javax.swing.*;class TtpDemo extends JFrame {
TtpDemo() {
super("卡片选项页面示例");
setSize(300, 200);
setVisible(true);
JTabbedPane jtp = new JTabbedPane();
ImageIcon icon1 = new ImageIcon("c1.gif");
ImageIcon icon2 = new ImageIcon("c2.gif");
ImageIcon icon3 = new ImageIcon("c3.gif");
jtp.addTab("城市", icon1, new CitiesPanel(), "城市名称");
jtp.addTab("文学", icon2, new BookPanel(), "文学书目");
jtp.addTab("网站", icon3, new NetPanel(), "精选网址");
getContentPane().add(jtp);
validate();
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}class CitiesPanel extends JPanel implements ActionListener {
JButton b1 = new JButton("北京");
JButton b2 = new JButton("上海");
JButton b3 = new JButton("深圳");
JButton b4 = new JButton("厦门"); CitiesPanel() {
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
add(b1);
add(b2);
add(b3);
add(b4);
} public void actionPerformed(ActionEvent e) {
try {
if (e.getSource() == b1) {
String URL = "\"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE\"http://www.163.com";
Process pp = Runtime.getRuntime().exec(URL);
}
if (e.getSource() == b2) {
String URL = "\"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE\"http://www.sina.com";
Process pp = Runtime.getRuntime().exec(URL);
}
if (e.getSource() == b3) {
String URL = "\"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE\"http://www.126.com";
Process pp = Runtime.getRuntime().exec(URL);
}
if (e.getSource() == b4) {
String URL = "\"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE\"http://www.sohu.com";
Process pp = Runtime.getRuntime().exec(URL);
}
} catch (Exception ex) { }
}
}class BookPanel extends JPanel {
BookPanel() {
JCheckBox cb1 = new JCheckBox("西游记");
JCheckBox cb2 = new JCheckBox("三国演义");
JCheckBox cb3 = new JCheckBox("红楼梦");
add(cb1);
add(cb2);
add(cb3);
}
}class NetPanel extends JPanel {
NetPanel() {
JComboBox jcb = new JComboBox();
jcb.addItem("思维论坛");
jcb.addItem("百度摸索");
jcb.addItem("爱好者");
add(jcb);
}
}public class Example5_7 {
public static void main(String args[]) {
new TtpDemo();
}
}