codice:
private void initLabel()
{
this.nemici = new JLabel[7];
for (int i = 0; i < 7; i++)
{
this.nemici[i] = new JLabel(new ImageIcon(getClass().getResource("/gioco/file/images/nemico.png")));
this.nemici[i].setVisible(true);
this.nemici[i].setSize(85, 55);
this.nemici[i].setLocation((i * 79), -80);
this.jPanel1.add(this.nemici[i]);
}
}
public void energya()
{
int a= Energia.getValue();
if (a==0)
{
String y= lbLifeV.getText();
int x=Integer.parseInt(y);
x=x-1;
y=Integer.toString(x);
lbLifeV.setText(y);
}
}
public Game2()
{
initComponents();
this.win.setVisible(false);
this.fuoco.setVisible(false);
initLabel();
this.addMouseMotionListener(new Mouse());
this.addMouseListener(new Mouse());
new Aerei().start();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
aereo = new javax.swing.JLabel();
fuocherello = new javax.swing.JLabel();
win = new javax.swing.JLabel();
fuoco = new javax.swing.JLabel();
lbScore = new javax.swing.JLabel();
lbScoreV = new javax.swing.JLabel();
lbLife = new javax.swing.JLabel();
lbLifeV = new javax.swing.JLabel();
Energia = new javax.swing.JProgressBar();
lbenergy = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Aereo battle- by Giancarlo Mennillo");
setResizable(false);
jPanel1.setBackground(new java.awt.Color(0, 0, 204));
jPanel1.setMinimumSize(new java.awt.Dimension(894, 745));
jPanel1.setPreferredSize(new java.awt.Dimension(894, 745));
aereo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gioco/file/images/aereo.png"))); // NOI18N
win.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gioco/file/images/win.png"))); // NOI18N
fuoco.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gioco/file/images/fuoco.png"))); // NOI18N
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(fuocherello)
.addGap(845, 845, 845))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(263, 263, 263)
.addComponent(fuoco)
.addContainerGap(559, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(247, 247, 247)
.addComponent(aereo)
.addContainerGap(541, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(120, 120, 120)
.addComponent(win)
.addContainerGap(435, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(win)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 254, Short.MAX_VALUE)
.addComponent(fuoco)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(aereo)
.addGap(23, 23, 23)
.addComponent(fuocherello))
);
lbScore.setFont(new java.awt.Font("Tahoma", 0, 24));
lbScore.setText("Score:");
lbScoreV.setFont(new java.awt.Font("Tahoma", 0, 24));
lbScoreV.setText("0");
lbLife.setFont(new java.awt.Font("Tahoma", 0, 24));
lbLife.setText("Lives:");
lbLifeV.setFont(new java.awt.Font("Tahoma", 0, 24));
lbLifeV.setText("3");
Energia.setForeground(new java.awt.Color(255, 0, 51));
lbenergy.setFont(new java.awt.Font("Tahoma", 0, 24));
lbenergy.setText("Energy:");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(26, 26, 26)
.addComponent(lbScore)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(lbScoreV)
.addGap(119, 119, 119)
.addComponent(lbLife)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lbLifeV)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 67, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(lbenergy)
.addGap(63, 63, 63))
.addGroup(layout.createSequentialGroup()
.addComponent(Energia, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())))
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 562, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(lbenergy)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Energia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbScore, javax.swing.GroupLayout.DEFAULT_SIZE, 43, Short.MAX_VALUE)
.addComponent(lbScoreV, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lbLife, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lbLifeV, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 590, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
public static void main(String args[])
{
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
Game2 a=new Game2();
Dimension screen= Toolkit.getDefaultToolkit().getScreenSize();
int x=(screen.width-a.getSize().width)/2;
int y=(screen.height-a.getSize().height)/2;
a.setLocation(x, y);
a.setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JProgressBar Energia;
private javax.swing.JLabel aereo;
private javax.swing.JLabel fuocherello;
private javax.swing.JLabel fuoco;
private javax.swing.JPanel jPanel1;
private javax.swing.JLabel lbLife;
public static javax.swing.JLabel lbLifeV;
private javax.swing.JLabel lbScore;
public static javax.swing.JLabel lbScoreV;
private javax.swing.JLabel lbenergy;
private javax.swing.JLabel win;
// End of variables declaration
}
gli altri file del package altro non sono ke le immagini .png che ho usato per creare gli aerei, il fuoco, gli aerei nemici, e dei palloncini che compaiono quando si vince....in realtà è un solo file java però ho creato un package nel caso avessi avuto bisogno di aggiungere dei file....