|
|
|
ช่วยทำเกมส์ ยิงลูกแก้วแบบแนว Puzzle Bobble หน่อยครับ |
|
|
|
|
|
|
|
คือผมต้องทำโปรเจคส่งอาจารย์น่ะครับ เป็นเกมส์ยิงลูกแก้วตอนนี้เริ่มทำไปหน่อยแล้วติดปัญหา netbeans กดปุ่มแล้วไม่ลิงค์ไปอีกคลาสกับสร้างตัวยิงบอลครับ รบกวนด้วยนะครับ ใครมีแนวโค้ดส่งมาให้ด้วยนะครับ
JFrame Form
Code (Java)
package ballshoot;
import javax.swing.JFrame;
public class Menu extends javax.swing.JFrame {
public Menu() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
initComponents();
setResizable(false);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton3 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setAutoRequestFocus(false);
getContentPane().setLayout(null);
jButton3.setFont(new java.awt.Font("Lucida Calligraphy", 0, 36)); // NOI18N
jButton3.setText("Start");
jButton3.setActionCommand("Start");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
getContentPane().add(jButton3);
jButton3.setBounds(260, 70, 140, 60);
jButton2.setFont(new java.awt.Font("Lucida Calligraphy", 0, 36)); // NOI18N
jButton2.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jButton2.setLabel("Quit");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
getContentPane().add(jButton2);
jButton2.setBounds(260, 150, 138, 60);
jLabel2.setIcon(new javax.swing.ImageIcon("C:\\Users\\User\\Documents\\NetBeansProjects\\JavaApplication27\\bg.jpg")); // NOI18N
getContentPane().add(jLabel2);
jLabel2.setBounds(0, 0, 610, 320);
setSize(new java.awt.Dimension(625, 359));
setLocationRelativeTo(null);
}// </editor-fold>
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
this.dispose();
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
Part1 f2 = new Part1();
f2.setVisible(true);
}
public static void main(String args[]) {
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
java.awt.EventQueue.invokeLater(() -> {
new Menu().setVisible(true);
});
}
// Variables declaration - do not modify
public javax.swing.JButton jButton2;
public javax.swing.JButton jButton3;
private javax.swing.JLabel jLabel2;
// End of variables declaration
}
Java ClassCode (Java)
package ballshoot;
import java.awt.*;
import javax.swing.*;
import javax.swing.JFrame;
public class Part1 {
public static void main(String[] args){
JFrame window=new JFrame("Bubble Shooter");
window.setSize(320,600);
window.setResizable(false);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
window.setLocationRelativeTo(null);
window.add(new graphic());
}
Java Class
Code (Java)
package ballshoot;
import java.awt.*;
import javax.swing.JPanel;
public class graphic extends JPanel{
public graphic() {
}
@Override
public void paint(Graphics g) {
Image img = Toolkit.getDefaultToolkit().getImage("bg1.jpg");
super.paint(g);
g.drawImage(img,0,0,null);
g.fillOval(10,35,30,30);
g.setColor(Color.CYAN);
Color[] colorBall = {Color.orange, Color.CYAN, Color.RED, Color.GREEN, Color.MAGENTA};
for(int i = 0; i < 10; i++) {
for(int j = 0; j < 5; j++){
int r = (int) (Math.random()*5);
Graphics2D g2d=(Graphics2D)g;
g.fillOval(10+(i*30), (35+(j*30)), 30, 30);
g.setColor(colorBall[r]);
}
}
}
}
ตัวยิงขอแค่เป็นเส้นคาดเดาแบบจุดๆไปอ่ะครับ T^T
Tag : Java
|
|
|
|
|
|
Date :
2016-11-17 19:17:35 |
By :
codeanon |
View :
1359 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2016-11-23 09:19:11 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|