主题:java中的运行出错
import java.awt.*;
import java.math.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;
import java.io.*;
import java.net.*;
import java.util.*;
import java.applet.*;
import javax.swing.Timer;
import javax.imageio.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.awt.FlowLayout;
public class Christmas {
public static void main(String[] args) {
// Create application frame.
ChristmasFrame frame = new ChristmasFrame();
// Show frame
frame.setVisible(true);
}
}
//create a Christmasframe
class ChristmasFrame extends JFrame
{
ChristmasFrame()
{
//define the title and size
setTitle("Merry Christmas~~");
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
//add the index panel
ChristmasPanel_1 panel_1 = new ChristmasPanel_1();
add(panel_1);
panel_1.start();
}
//create the index
class ChristmasPanel_1 extends JPanel
{
ChristmasPanel_1()
{
//add a backsound
try
{
sound1=Applet.newAudioClip(new URL("file:" + System.getProperty("user.dir") + "/"+"1.wav"));
}
catch(IOException e)
{
e.printStackTrace();
}
sound1.play();
//add a image to the panel
try
{
image1=ImageIO.read(new File("01.jpg"));
}
catch(IOException e)
{
e.printStackTrace();
}
setLayout(null);
//add a label to the panel
o1=new JLabel("Welcome in");
o1.setBounds(120,10,500,50);
add(o1);
//add a button to the panel
button1 = new JButton("go");
RepaintPanel listener1 = new RepaintPanel();
button1.addActionListener(listener1);
button1.setBounds(540,360,50,30);
add(button1);
}
class RepaintPanel implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
//remove ChristmasPanel_1 and create ChristmasPanel_2
ChristmasPanel_1.this.sound1.stop();
ChristmasPanel_1.this.setVisible(false);
ChristmasPanel_2 panel_2 = new ChristmasPanel_2();
ChristmasFrame.this.add(panel_2);
panel_2.start2();
}
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if(image1==null) return;
g.drawImage(image1,0,0,null);
}
public void start()
{
ActionListener listeners = new WelcomePrainter();
Timer t = new Timer(800,listeners);
t.start();
}
private class WelcomePrainter extends JPanel implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
int i = (int)(Math.random()*255);
int j = (int)(Math.random()*255);
int k = (int)(Math.random()*255);
o1.setForeground(new Color(i,j,k));
o1.setFont(new Font("楷体",Font.BOLD,50));
o1.setText("Merry Christmas");
}
}
private Image image1;
private AudioClip sound1;
private JLabel o1;
private JButton button1;
}
//create ChristmasPanel_2
class ChristmasPanel_2 extends JPanel
{
ChristmasPanel_2()
{
//add a backsound
try
{
sound2=Applet.newAudioClip(new URL("file:" + System.getProperty("user.dir") + "/"+"2.wav"));
}
catch(IOException e)
{
e.printStackTrace();
}
sound2.play();
//add a image to the panel
try
{
image2=ImageIO.read(new File("02.jpg"));
}
catch(IOException e)
{
e.printStackTrace();
}
setLayout(null);
//creat the words
// JLabel[] o2= new JLabel[3];
o2[0] = new JLabel("Christmas is drawing");
o2[1] = new JLabel("Are you ready to this year's Christmas Day ?");
o2[2] = new JLabel("Look at what I prepared for you...");
count = 0;
for(JLabel i:o2)
add(i);
for(JLabel j:o2)
j.setVisible(false);
// add button the panel
button2 = new JButton("NEXT->");
ThirdPage listener2 = new ThirdPage();
button2.addActionListener(listener2);
button2.setBounds(530,360,60,30);
add(button2);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if(image2==null) return;
g.drawImage(image2,0,0,null);
}
public void start2()
{
ActionListener listener2 = new SecondText();
Timer t = new Timer(1000,listener2);
t.start();
}
private class SecondText implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
if(count<=2)
{ o2[count].setBounds(300,20+count*50,200,200);
o2[count].setVisible(true);
}
count++;
}
}
private class ThirdPage extends JPanel implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
ChristmasPanel_2.this.sound2.stop();
ChristmasPanel_2.this.setVisible(false);
ChristmasPanel_3 panel_3 = new ChristmasPanel_3();
ChristmasFrame.this.add(panel_3);
panel_3.start3();
}
}
private Image image2;
private AudioClip sound2;
private int count;
public JLabel[] o2 = new JLabel[3];
private JButton button2;
}
//create ChristmasPanel_3
class ChristmasPanel_3 extends JPanel
{
ChristmasPanel_3()
{
//add a backsound
try
{
sound3=Applet.newAudioClip(new URL("file:" + System.getProperty("user.dir") + "/"+"3.wav"));
}
catch(IOException e)
{
e.printStackTrace();
}
sound3.play();
//add a image to the panel
try
{
image4=ImageIO.read(new File("09.jpg"));
}
catch(IOException e)
{
e.printStackTrace();
}
setLayout(null);
//add three buttons to the panel
JButton button4 = new JButton("NEXT->");
ForthPage listener4 = new ForthPage();
button4.addActionListener(listener4);
button4.setBounds(530,360,60,30);
add(button4);
//add the wishies
o3[0] = new JLabel("Dear Au:");
o3[1] = new JLabel("Merry Christmas and Happy New Year");
o3[2] = new JLabel("All Wishes for you!");
o3[3] = new JLabel(" Yours Ivy");
o3[4] = new JLabel(" 2007 12.2");
count = 0;
for(JLabel i:o3)
{ i.setBounds(50,50,300,50);
add(i);
i.setVisible(false);
}
}
public void start3()
{
ActionListener listener3 = new ThirdText();
Timer t = new Timer(1000,listener3);
t.start();
}
private class ThirdText implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
if(count<=4)
{ o3[count].setBounds(200,20+count*50,200,200);
o3[count].setVisible(true);
}
count++;
}
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if(image4==null) return;
g.drawImage(image4,0,0,null);
}
class ForthPage implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
ChristmasPanel_3.this.sound3.stop();
ChristmasPanel_3.this.setVisible(true);
ChristmasPanel_4 panel_4 = new ChristmasPanel_4();
ChristmasFrame.this.add(panel_4);
// panel_2.start2();
}
}
public int count;
private Image image4;
private AudioClip sound3;
public JLabel[] o3 = new JLabel[5];
}
//create ChristmasPanel_4
class ChristmasPanel_4 extends JPanel
{
ChristmasPanel_4()
{//add a backsound
/* try
{
sound4=Applet.newAudioClip(new URL("file:" + System.getProperty("user.dir") + "/"+"2.wav"));
}
catch(IOException e)
{
e.printStackTrace();
}
sound4.play();*/
//add a image to the panel
try
{
image4=ImageIO.read(new File("06.jpg"));
}
catch(IOException e)
{
e.printStackTrace();
}
setLayout(null);
o3 = new JLabel("Miss you~~");
o3.setBounds(200,20,200,50);
add(o3);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if(image4==null) return;
g.drawImage(image4,0,0,null);
}
private JLabel o3;
private Image image4;
private AudioClip sound4;
}
public static final int DEFAULT_WIDTH = 600;
public static final int DEFAULT_HEIGHT = 435;
}
提示:
at javax.imageio.ImageIO.read(Unknown Source)
at ChristmasFrame$ChristmasPanel_1.<init>(Christmas.java:68)
at ChristmasFrame.<init>(Christmas.java:43)
at Christmas.main(Christmas.java:26)
运行时,没有图画和音乐,
用JCREATER时,图画和音乐文件放在CLASS中,
用ECLIPSE时,图画和音乐文件放在BIN 中,
请教错 误出在哪里?
还有怎样将其转化成不依赖于JRE的.exe文件,即可以在不装JAVA的机子上运行?
import java.math.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.*;
import java.io.*;
import java.net.*;
import java.util.*;
import java.applet.*;
import javax.swing.Timer;
import javax.imageio.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.awt.FlowLayout;
public class Christmas {
public static void main(String[] args) {
// Create application frame.
ChristmasFrame frame = new ChristmasFrame();
// Show frame
frame.setVisible(true);
}
}
//create a Christmasframe
class ChristmasFrame extends JFrame
{
ChristmasFrame()
{
//define the title and size
setTitle("Merry Christmas~~");
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
//add the index panel
ChristmasPanel_1 panel_1 = new ChristmasPanel_1();
add(panel_1);
panel_1.start();
}
//create the index
class ChristmasPanel_1 extends JPanel
{
ChristmasPanel_1()
{
//add a backsound
try
{
sound1=Applet.newAudioClip(new URL("file:" + System.getProperty("user.dir") + "/"+"1.wav"));
}
catch(IOException e)
{
e.printStackTrace();
}
sound1.play();
//add a image to the panel
try
{
image1=ImageIO.read(new File("01.jpg"));
}
catch(IOException e)
{
e.printStackTrace();
}
setLayout(null);
//add a label to the panel
o1=new JLabel("Welcome in");
o1.setBounds(120,10,500,50);
add(o1);
//add a button to the panel
button1 = new JButton("go");
RepaintPanel listener1 = new RepaintPanel();
button1.addActionListener(listener1);
button1.setBounds(540,360,50,30);
add(button1);
}
class RepaintPanel implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
//remove ChristmasPanel_1 and create ChristmasPanel_2
ChristmasPanel_1.this.sound1.stop();
ChristmasPanel_1.this.setVisible(false);
ChristmasPanel_2 panel_2 = new ChristmasPanel_2();
ChristmasFrame.this.add(panel_2);
panel_2.start2();
}
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if(image1==null) return;
g.drawImage(image1,0,0,null);
}
public void start()
{
ActionListener listeners = new WelcomePrainter();
Timer t = new Timer(800,listeners);
t.start();
}
private class WelcomePrainter extends JPanel implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
int i = (int)(Math.random()*255);
int j = (int)(Math.random()*255);
int k = (int)(Math.random()*255);
o1.setForeground(new Color(i,j,k));
o1.setFont(new Font("楷体",Font.BOLD,50));
o1.setText("Merry Christmas");
}
}
private Image image1;
private AudioClip sound1;
private JLabel o1;
private JButton button1;
}
//create ChristmasPanel_2
class ChristmasPanel_2 extends JPanel
{
ChristmasPanel_2()
{
//add a backsound
try
{
sound2=Applet.newAudioClip(new URL("file:" + System.getProperty("user.dir") + "/"+"2.wav"));
}
catch(IOException e)
{
e.printStackTrace();
}
sound2.play();
//add a image to the panel
try
{
image2=ImageIO.read(new File("02.jpg"));
}
catch(IOException e)
{
e.printStackTrace();
}
setLayout(null);
//creat the words
// JLabel[] o2= new JLabel[3];
o2[0] = new JLabel("Christmas is drawing");
o2[1] = new JLabel("Are you ready to this year's Christmas Day ?");
o2[2] = new JLabel("Look at what I prepared for you...");
count = 0;
for(JLabel i:o2)
add(i);
for(JLabel j:o2)
j.setVisible(false);
// add button the panel
button2 = new JButton("NEXT->");
ThirdPage listener2 = new ThirdPage();
button2.addActionListener(listener2);
button2.setBounds(530,360,60,30);
add(button2);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if(image2==null) return;
g.drawImage(image2,0,0,null);
}
public void start2()
{
ActionListener listener2 = new SecondText();
Timer t = new Timer(1000,listener2);
t.start();
}
private class SecondText implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
if(count<=2)
{ o2[count].setBounds(300,20+count*50,200,200);
o2[count].setVisible(true);
}
count++;
}
}
private class ThirdPage extends JPanel implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
ChristmasPanel_2.this.sound2.stop();
ChristmasPanel_2.this.setVisible(false);
ChristmasPanel_3 panel_3 = new ChristmasPanel_3();
ChristmasFrame.this.add(panel_3);
panel_3.start3();
}
}
private Image image2;
private AudioClip sound2;
private int count;
public JLabel[] o2 = new JLabel[3];
private JButton button2;
}
//create ChristmasPanel_3
class ChristmasPanel_3 extends JPanel
{
ChristmasPanel_3()
{
//add a backsound
try
{
sound3=Applet.newAudioClip(new URL("file:" + System.getProperty("user.dir") + "/"+"3.wav"));
}
catch(IOException e)
{
e.printStackTrace();
}
sound3.play();
//add a image to the panel
try
{
image4=ImageIO.read(new File("09.jpg"));
}
catch(IOException e)
{
e.printStackTrace();
}
setLayout(null);
//add three buttons to the panel
JButton button4 = new JButton("NEXT->");
ForthPage listener4 = new ForthPage();
button4.addActionListener(listener4);
button4.setBounds(530,360,60,30);
add(button4);
//add the wishies
o3[0] = new JLabel("Dear Au:");
o3[1] = new JLabel("Merry Christmas and Happy New Year");
o3[2] = new JLabel("All Wishes for you!");
o3[3] = new JLabel(" Yours Ivy");
o3[4] = new JLabel(" 2007 12.2");
count = 0;
for(JLabel i:o3)
{ i.setBounds(50,50,300,50);
add(i);
i.setVisible(false);
}
}
public void start3()
{
ActionListener listener3 = new ThirdText();
Timer t = new Timer(1000,listener3);
t.start();
}
private class ThirdText implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
if(count<=4)
{ o3[count].setBounds(200,20+count*50,200,200);
o3[count].setVisible(true);
}
count++;
}
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if(image4==null) return;
g.drawImage(image4,0,0,null);
}
class ForthPage implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
ChristmasPanel_3.this.sound3.stop();
ChristmasPanel_3.this.setVisible(true);
ChristmasPanel_4 panel_4 = new ChristmasPanel_4();
ChristmasFrame.this.add(panel_4);
// panel_2.start2();
}
}
public int count;
private Image image4;
private AudioClip sound3;
public JLabel[] o3 = new JLabel[5];
}
//create ChristmasPanel_4
class ChristmasPanel_4 extends JPanel
{
ChristmasPanel_4()
{//add a backsound
/* try
{
sound4=Applet.newAudioClip(new URL("file:" + System.getProperty("user.dir") + "/"+"2.wav"));
}
catch(IOException e)
{
e.printStackTrace();
}
sound4.play();*/
//add a image to the panel
try
{
image4=ImageIO.read(new File("06.jpg"));
}
catch(IOException e)
{
e.printStackTrace();
}
setLayout(null);
o3 = new JLabel("Miss you~~");
o3.setBounds(200,20,200,50);
add(o3);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
if(image4==null) return;
g.drawImage(image4,0,0,null);
}
private JLabel o3;
private Image image4;
private AudioClip sound4;
}
public static final int DEFAULT_WIDTH = 600;
public static final int DEFAULT_HEIGHT = 435;
}
提示:
at javax.imageio.ImageIO.read(Unknown Source)
at ChristmasFrame$ChristmasPanel_1.<init>(Christmas.java:68)
at ChristmasFrame.<init>(Christmas.java:43)
at Christmas.main(Christmas.java:26)
运行时,没有图画和音乐,
用JCREATER时,图画和音乐文件放在CLASS中,
用ECLIPSE时,图画和音乐文件放在BIN 中,
请教错 误出在哪里?
还有怎样将其转化成不依赖于JRE的.exe文件,即可以在不装JAVA的机子上运行?