import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.Timer;
import java.applet.*;
import javax.sound.sampled.*;
import java.net.URL;
public class OOPASS2 extends JFrame /*implements ActionListener,MouseListener,MouseMotionListener*/
{
int ex,ey;
ImageIcon image1 = new ImageIcon("Gun.png");
ImageIcon image2 = new ImageIcon("Gun2.png");
ImageIcon image3 = new ImageIcon("cross.png");
ImageIcon image4 = new ImageIcon("brick.png");
AudioClip bg;
Timer swTimer;
Coor obj;
Container c;
public void main(String[] args){
JFrame frame = new JFrame("asd");
c=getContentPane();
c.setLayout(new FlowLayout());
//bg = getAudioClip(getDocumentBase(),"fire.wav");
URL urlClick = getClass().getResource("fire.wav");
bg = Applet.newAudioClip(urlClick);
setSize(900, 500);
//addMouseListener(this);
//addMouseMotionListener(this);
frame.setSize(300,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
/*public void actionPerformed(ActionEvent event )
{
repaint();
}*/
/*public void mousePressed(MouseEvent event)
{
Graphics g= getGraphics();
super.paint(g);
int x = 20 + (int) (Math.random() * 850);
image4.paintIcon(this,g,1,370);
image2.paintIcon(this,g,ex,300);
bg.play();
}
public void mouseReleased(MouseEvent event)
{
Graphics g= getGraphics();
super.paint(g);
int x = 20 + (int) (Math.random() * 850);
image4.paintIcon(this,g,1,370);
image1.paintIcon(this,g,ex,300);
}
public void mouseClicked(MouseEvent event)
{
}
public void mouseEntered(MouseEvent event)
{
}
public void mouseExited(MouseEvent event)
{
}
public void mouseDragged(MouseEvent e)
{
}
public void mouseMoved(MouseEvent e)
{
Graphics g= getGraphics();
super.paint(g);
ex=e.getX();
ey=e.getY();
image3.paintIcon(this,g,ex-48,ey-36);
image4.paintIcon(this,g,1,370);
image1.paintIcon(this,g,ex,300);
}
public void paint(Graphics g){
int x = 20 + (int) (Math.random() * 850);
int y = 20 + (int) (Math.random() * 450);
super.paint(g);
image4.paintIcon(this,g,1,370);
image1.paintIcon(this,g,200,340);
}*/
}
ผม คอมเม้นไว้เหลือๆ นิดๆหน่อย ไม่กี่โค้ด แต่ก็ยังไม่ออก Error Main อะไรไม่รู้ตอนรัน
Java JFrame ไม่ออก ช่วยทีครับ
import java.awt.*;
import java.awt.event.*;
import javax.swing.Timer;
import java.applet.*;
import javax.sound.sampled.*;
import java.net.URL;
public class OOPASS2 extends JFrame /*implements ActionListener,MouseListener,MouseMotionListener*/
{
int ex,ey;
ImageIcon image1 = new ImageIcon("Gun.png");
ImageIcon image2 = new ImageIcon("Gun2.png");
ImageIcon image3 = new ImageIcon("cross.png");
ImageIcon image4 = new ImageIcon("brick.png");
AudioClip bg;
Timer swTimer;
Coor obj;
Container c;
public void main(String[] args){
JFrame frame = new JFrame("asd");
c=getContentPane();
c.setLayout(new FlowLayout());
//bg = getAudioClip(getDocumentBase(),"fire.wav");
URL urlClick = getClass().getResource("fire.wav");
bg = Applet.newAudioClip(urlClick);
setSize(900, 500);
//addMouseListener(this);
//addMouseMotionListener(this);
frame.setSize(300,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
/*public void actionPerformed(ActionEvent event )
{
repaint();
}*/
/*public void mousePressed(MouseEvent event)
{
Graphics g= getGraphics();
super.paint(g);
int x = 20 + (int) (Math.random() * 850);
image4.paintIcon(this,g,1,370);
image2.paintIcon(this,g,ex,300);
bg.play();
}
public void mouseReleased(MouseEvent event)
{
Graphics g= getGraphics();
super.paint(g);
int x = 20 + (int) (Math.random() * 850);
image4.paintIcon(this,g,1,370);
image1.paintIcon(this,g,ex,300);
}
public void mouseClicked(MouseEvent event)
{
}
public void mouseEntered(MouseEvent event)
{
}
public void mouseExited(MouseEvent event)
{
}
public void mouseDragged(MouseEvent e)
{
}
public void mouseMoved(MouseEvent e)
{
Graphics g= getGraphics();
super.paint(g);
ex=e.getX();
ey=e.getY();
image3.paintIcon(this,g,ex-48,ey-36);
image4.paintIcon(this,g,1,370);
image1.paintIcon(this,g,ex,300);
}
public void paint(Graphics g){
int x = 20 + (int) (Math.random() * 850);
int y = 20 + (int) (Math.random() * 450);
super.paint(g);
image4.paintIcon(this,g,1,370);
image1.paintIcon(this,g,200,340);
}*/
}
ผม คอมเม้นไว้เหลือๆ นิดๆหน่อย ไม่กี่โค้ด แต่ก็ยังไม่ออก Error Main อะไรไม่รู้ตอนรัน