Hey Leute,
ich weiß nicht ob das hier so recht ein Anfänger-Thema ist, aber ich denke schon. Versucht auch ein wenig über das Chaos hinweg zu sehen und die Tatsache das ich mit null-Layout arbeite, ist lediglich eine Erst-Version eines geplanten Spiels von mir.
Die Problematik steht ja schon im Titel, allerdings wiederhole ich es nochmal. Das Programm arbeitet derzeit mit vielen Labeln und sobald auf ein Label geklickt wird (aktuell nur für drei vergeben) wird ein Fester geöffnet mit Bau-Optionen. So weit so gut, wird auch geöffnet, lediglich wird mir der Inhalt nicht angezeigt. Ich denke der Grund dafür ist voll offensichtlich und ich sehe den nur nicht.
Code: (betrifft unten JFrame Class benannt als Options)
Geplant ist in der zweiten Version das Level per Zufall aufgebaut werden und ich werde die einzelnen Planeten dann in einem Array abspeichern. Ebenso wird die Verteilung der einzelnen Label zu einer Methode gemacht. Sitze da erst seit einem Abend dran, von daher ist das insgesamt ausbaufähig.
Gruß Alexander
ich weiß nicht ob das hier so recht ein Anfänger-Thema ist, aber ich denke schon. Versucht auch ein wenig über das Chaos hinweg zu sehen und die Tatsache das ich mit null-Layout arbeite, ist lediglich eine Erst-Version eines geplanten Spiels von mir.
Die Problematik steht ja schon im Titel, allerdings wiederhole ich es nochmal. Das Programm arbeitet derzeit mit vielen Labeln und sobald auf ein Label geklickt wird (aktuell nur für drei vergeben) wird ein Fester geöffnet mit Bau-Optionen. So weit so gut, wird auch geöffnet, lediglich wird mir der Inhalt nicht angezeigt. Ich denke der Grund dafür ist voll offensichtlich und ich sehe den nur nicht.
Code: (betrifft unten JFrame Class benannt als Options)
Java:
import java.io.*;
import java.util.*;
import java.nio.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.IOException;
import java.io.FileNotFoundException;
public class RootsOfAnEmpire extends JFrame implements ActionListener
{
WindowListener myWindowListener = new WindowListener ();
//CALCULATION VARIABLES
int counter=0, m=1, e=1, p=1, mf=1, ef=1, pf=1;
//YOUR VARIABLES
int buildings=0, matter=0, energie=0, population=0, satisfaction=100, power=0, imperial=13;
//FOE VARIABLES
int buildingsf=0, matterf=0, energief=0, populationf=0, satisfactionf=100, powerf=0, imperialf=13;
Panel navigation, operation;
public RootsOfAnEmpire ()
{
setTitle("Roots of an Empire");
//LAYOUT
this.setVisible (true);
this.setSize (1280,860);
this.setLayout (null);
//NAVIGATIONS PICTURES
ImageIcon stars = new ImageIcon("Sterne.jpg");
ImageIcon planet = new ImageIcon("hexa.png");
ImageIcon planety = new ImageIcon("hexaP.png");
ImageIcon planetf = new ImageIcon("hexaPF.png");
ImageIcon begin = new ImageIcon("start.png");
ImageIcon pass = new ImageIcon("end.png");
//RESSOURCE PICTUTERES
ImageIcon mat = new ImageIcon("matter.png");
ImageIcon ene = new ImageIcon("energie.png");
ImageIcon pop = new ImageIcon("population.png");
//LIST OF LABELS
JLabel matterlabel = new JLabel(mat);
JLabel energielabel = new JLabel(ene);
JLabel populationlabel = new JLabel(pop);
JLabel background = new JLabel(stars);
JLabel start = new JLabel(begin);
JLabel end = new JLabel(pass);
JLabel planet1 = new JLabel(planety);
JLabel planet16 = new JLabel(planetf);
JLabel planet2 = new JLabel(planet);
JLabel planet3 = new JLabel(planet);
JLabel planet4 = new JLabel(planet);
JLabel planet5 = new JLabel(planet);
JLabel planet6 = new JLabel(planet);
JLabel planet7 = new JLabel(planet);
JLabel planet8 = new JLabel(planet);
JLabel planet9 = new JLabel(planet);
JLabel planet10 = new JLabel(planet);
JLabel planet11 = new JLabel(planet);
JLabel planet12 = new JLabel(planet);
JLabel planet13 = new JLabel(planet);
JLabel planet14 = new JLabel(planet);
JLabel planet15 = new JLabel(planet);
//ADD OBJECTS
navigation = new Panel();
navigation.add (matterlabel);
matterlabel.setBounds(200,25,107,120);
navigation.add (energielabel);
energielabel.setBounds(500,25,107,120);
navigation.add (populationlabel);
populationlabel.setBounds(800,25,107,120);
navigation.add (planet1);
planet1.setBounds(582,660,107,120);
navigation.add (planet2);
planet2.setBounds(634,571,107,120);
navigation.add (planet3);
planet3.setBounds(530,571,107,120);
navigation.add (planet4);
planet4.setBounds(686,482,107,120);
navigation.add (planet5);
planet5.setBounds(478,482,107,120);
navigation.add (planet6);
planet6.setBounds(582,482,107,120);
navigation.add (planet7);
planet7.setBounds(426,393,107,120);
navigation.add (planet8);
planet8.setBounds(634,393,107,120);
navigation.add (planet9);
planet9.setBounds(530,393,107,120);
navigation.add (planet10);
planet10.setBounds(738,393,107,120);
navigation.add (planet11);
planet11.setBounds(582,309,107,120);
navigation.add (planet12);
planet12.setBounds(686,309,107,120);
navigation.add (planet13);
planet13.setBounds(478,309,107,120);
navigation.add (planet14);
planet14.setBounds(634,225,107,120);
navigation.add (planet15);
planet15.setBounds(530,225,107,120);
navigation.add (planet16);
planet16.setBounds(582,141,107,120);
navigation.add (start);
start.setBounds(1125,25,107,120);
navigation.add (background);
background.setBounds(0,0,1280,860);
navigation.setBounds(0,0,1280,860);
this.add (navigation);
start.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent me)
{
int a=(int)(Math.random()*100)+1;
if (counter==0)
{
if (a>50)
{
JOptionPane.showMessageDialog(null,"The Test-AI starts the game!","Hint", JOptionPane.CANCEL_OPTION);
}
if (a<=50)
{
JOptionPane.showMessageDialog(null,"You will start the game!","Hint", JOptionPane.CANCEL_OPTION);
}
start.setIcon(pass);
}
else
{
//ADDS RESSOURCES FOR THE TURN
matter=matter+m;
energie=energie+e;
population=population+p;
matterf=matterf+mf;
energief=energief+ef;
populationf=population+pf;
if (a>50)
{
a=49;
}
else
{
a=51;
}
}
counter=1;
}
});
planet1.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent me)
{
if (counter==0)
{
JOptionPane.showMessageDialog(null,"Push the Start-Button!","Hint", JOptionPane.CANCEL_OPTION);
}
else
{
Options op=new Options();
}
}
});
planet2.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent me)
{
if (counter==0)
{
JOptionPane.showMessageDialog(null,"Push the Start-Button!","Hint", JOptionPane.CANCEL_OPTION);
}
else
{
Options op=new Options();
}
}
});
planet3.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent me)
{
if (counter==0)
{
JOptionPane.showMessageDialog(null,"Push the Start-Button!","Hint", JOptionPane.CANCEL_OPTION);
}
else
{
Options op=new Options();
}
}
});
//CONNECTION WITH THE LISTENER
this.addWindowListener (myWindowListener);
}
public void actionPerformed(ActionEvent z)
{
//STRING COMMAND
String command = z.getActionCommand();
}
public void paint (Graphics g)
{
//g.drawImage(navigation, 0, 0,this);
//g.drawImage(background, 100, 0,this);
}
public void mouseClicked(MouseEvent me){}
public void mousePressed(MouseEvent me){}
public void mouseEntered(MouseEvent me){}
public void mouseExited(MouseEvent me){}
public void mouseReleased(MouseEvent me){}
public class Options extends JFrame
{
Panel operation;
public Options()
{
setTitle("Options");
//LAYOUT
this.setVisible (true);
this.setSize (600,500);
this.setLayout (null);
this.setLocation(700,300);
//OPTION PICTURES
ImageIcon star = new ImageIcon("star.jpg");
ImageIcon re = new ImageIcon("refinery.png");
ImageIcon pp = new ImageIcon("power plant.png");
ImageIcon co = new ImageIcon("colonize.png");
//LIST OF LABELS
JLabel back = new JLabel(star);
JLabel refinery = new JLabel(re);
JLabel powerplant = new JLabel(pp);
JLabel colonize = new JLabel(co);
operation = new Panel();
operation.add (refinery);
refinery.setBounds(10,10,75,100);
operation.add (powerplant);
powerplant.setBounds(95,10,75,100);
operation.add (colonize);
colonize.setBounds(180,10,75,100);
operation.add (back);
back.setBounds(0,0,600,500);
back.setBounds(0,0,600,500);
this.add (operation);
}
}
public class WindowListener extends WindowAdapter
{
public void windowClosing(WindowEvent ex)
{
System.exit (0);
}
}
public static void main (String args[])
{
new RootsOfAnEmpire ();
}
}
Geplant ist in der zweiten Version das Level per Zufall aufgebaut werden und ich werde die einzelnen Planeten dann in einem Array abspeichern. Ebenso wird die Verteilung der einzelnen Label zu einer Methode gemacht. Sitze da erst seit einem Abend dran, von daher ist das insgesamt ausbaufähig.
Gruß Alexander