Frostmourne Geschrieben 10. Januar 2005 Geschrieben 10. Januar 2005 Ich hab hier ein Problem mein KeyListener tut nich ich weiss nich warum hab schon alles Probiert! der MouseListener scheint auch nich in Ordnung zu sein ich habe zum test auf linke maustaste eine textausgabe gelegt wie beim KeyListener doch wenn ich die maustaste drücke macht er die funktion vom Keylistener mit aber der KeyListener tut garnich! kann mir jemand helfen was is mein Fehler! import javax.swing.*; import java.awt.*; import java.awt.event.*; class GameGUI extends JFrame implements ActionListener, KeyListener, MouseListener { private Button b1; private Button b2; private Map m; private JTextField tsystem; private TextField tchat; private TextArea tchat2; private JPanel panel1; private JPanel panel2; private JPanel panel3; private JPanel haupt; public GameGUI() { //Titel des Fensters bestimmen!!! setTitle("Game 1.0"); //Anfangs größe des Fensters setSize(600, 427); setResizable(false); setLocation(300, 150); //setUndecorated(true); addKeyListener(this); addMouseListener(this); m = new Map(); // Konstruiere die Menüzeile !!! MenuBar M1 = new MenuBar(); Menu menu = new Menu("Game"); MenuItem Mitem2 = new MenuItem("Optionen"); Mitem2.addActionListener(this); menu.add(Mitem2); MenuItem Mitem3 = new MenuItem("Hilfe"); Mitem3.addActionListener(this); menu.add(Mitem3); MenuItem Mitem4 = new MenuItem("Beenden"); Mitem4.addActionListener(this); menu.add(Mitem4); M1.add(menu); setMenuBar(M1); haupt = new JPanel(null); panel1 = new JPanel(new GridLayout()); panel1.setBounds(0, 0, 600, 250); //von links, von oben ,Länge, Breite panel2 = new JPanel(new FlowLayout()); panel2.setBounds(0, 250, 600, 150); //von links, von oben ,Länge, // Breite tsystem = new JTextField("", 41); tsystem.setFont(new Font("Arial", 1, 15)); tsystem.setHorizontalAlignment(SwingConstants.CENTER); tsystem.setEditable(false); tchat = new TextField("", 15); tchat.setFont(new Font("Arial", 3, 10)); tchat2 = new TextArea("", 4, 50); tchat2.setFont(new Font("Arial", 3, 10)); tchat2.setEditable(false); b1 = new Button("Runde beenden"); b1.addActionListener(this); b1.setBackground(Color.lightGray); b2 = new Button("Nachricht senden"); b2.setActionCommand("Senden"); b2.addActionListener(this); b2.setBackground(Color.lightGray); panel1.add(m); panel2.add(tsystem); panel2.add(tchat2); panel2.add(tchat); panel2.add(b2); panel2.add(b1); haupt.add(panel1); haupt.add(panel2); haupt.setVisible(true); panel1.setVisible(true); panel2.setVisible(true); Container einContainer = getContentPane(); einContainer.add(haupt); // Das Fenster mit X schließen !!! setDefaultCloseOperation(EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent evt) { String command = evt.getActionCommand(); { if (command.equals("Beenden")) { System.exit(0); } if (command.equals("Senden")) { String a = tchat.getText(); tchat2.setText(tchat2.getText() + "\n" + a); } } } public void keyPressed(KeyEvent event) { if (event.getKeyCode() == KeyEvent.VK_ENTER) { System.out.println("hg"); } } public void keyReleased(KeyEvent event) { } public void keyTyped(KeyEvent event) { } public void mouseClicked(MouseEvent mvt) { } public void mouseEntered(MouseEvent mvt) { } public void mouseExited(MouseEvent mvt) { } public void mousePressed(MouseEvent mvt) { } public void mouseReleased(MouseEvent mvt) { if (mvt.getButton() == 1) { System.out.println("as"); } if (mvt.getButton() == 3) { } repaint(); } public static void main(String[] args) { GameGUI gg = new GameGUI(); gg.start(); } public void start() { setVisible(true); } } Zitieren
Jaraz Geschrieben 10. Januar 2005 Geschrieben 10. Januar 2005 [bitte code tags benutzen] Hi, ich nehme mal an Map ist ne eigene Klasse von dir, weil so läuft der Code nicht. Der MouseListener funzt doch, KeyListener auf JFrame bei JDK 1.4 schau mal hier: http://forum.java.sun.com/thread.jspa?forumID=57&threadID=196288 Gruß Jaraz Zitieren
Frostmourne Geschrieben 11. Januar 2005 Autor Geschrieben 11. Januar 2005 Ja Map is ne eigene Klasse von mir aber bei mir funzt das nich! Hier die Map Klasse da mit ihr das probieren könnt! import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; class Map extends JPanel { private GameGUI gg; private int x=0; private int a1=0; public void paintComponent(Graphics g) { super.paintComponent(g); //Spalte1 int arx1[] = {70,50,40,50,70,80};// 2te unt 4te Zahl ändern um linke Seite abzuflachen rechte Seite= 1te und 5te int ary1[] = {40,40,60,80,80,60}; int ary2[] = {80,80,100,120,120,100}; int ary3[] = {120,120,140,160,160,140}; int ary4[] = {160,160,180,200,200,180}; //Spalte2 int arx2[] = {100,80,70,80,100,110}; int ary6[] = {20,20,40,60,60,40}; int ary7[] = {60,60,80,100,100,80}; int ary8[] = {100,100,120,140,140,120}; int ary9[] = {140,140,160,180,180,160}; int ary10[] = {180,180,200,220,220,200}; //Spalte3 int arx3[] = {130,110,100,110,130,140}; int ary12[] = {40,40,60,80,80,60}; int ary13[] = {80,80,100,120,120,100}; int ary14[] = {120,120,140,160,160,140}; int ary15[] = {160,160,180,200,200,180}; //Spalte4 int arx4[] = {160,140,130,140,160,170}; int ary16[] = {20,20,40,60,60,40}; int ary17[] = {60,60,80,100,100,80}; int ary18[] = {100,100,120,140,140,120}; int ary19[] = {140,140,160,180,180,160}; int ary20[] = {180,180,200,220,220,200}; //Spalte5 int arx5[] = {190,170,160,170,190,200}; int ary22[] = {40,40,60,80,80,60}; int ary23[] = {80,80,100,120,120,100}; int ary24[] = {120,120,140,160,160,140}; int ary25[] = {160,160,180,200,200,180}; //Spalte6 int arx6[] = {220,200,190,200,220,230}; int ary26[] = {20,20,40,60,60,40}; int ary27[] = {60,60,80,100,100,80}; int ary28[] = {100,100,120,140,140,120}; int ary29[] = {140,140,160,180,180,160}; int ary30[] = {180,180,200,220,220,200}; //Spalte7 int arx7[] = {250,230,220,230,250,260}; int ary32[] = {40,40,60,80,80,60}; int ary33[] = {80,80,100,120,120,100}; int ary34[] = {120,120,140,160,160,140}; int ary35[] = {160,160,180,200,200,180}; //Spalte8 int arx8[] = {280,260,250,260,280,290}; int ary36[] = {20,20,40,60,60,40}; int ary37[] = {60,60,80,100,100,80}; int ary38[] = {100,100,120,140,140,120}; int ary39[] = {140,140,160,180,180,160}; int ary40[] = {180,180,200,220,220,200}; //Spalte9 int arx9[] = {310,290,280,290,310,320}; int ary42[] = {40,40,60,80,80,60}; int ary43[] = {80,80,100,120,120,100}; int ary44[] = {120,120,140,160,160,140}; int ary45[] = {160,160,180,200,200,180}; //Spalte10 int arx10[] = {340,320,310,320,340,350}; int ary46[] = {20,20,40,60,60,40}; int ary47[] = {60,60,80,100,100,80}; int ary48[] = {100,100,120,140,140,120}; int ary49[] = {140,140,160,180,180,160}; int ary50[] = {180,180,200,220,220,200}; //Spalte11 int arx11[] = {370,350,340,350,370,380}; int ary52[] = {40,40,60,80,80,60}; int ary53[] = {80,80,100,120,120,100}; int ary54[] = {120,120,140,160,160,140}; int ary55[] = {160,160,180,200,200,180}; //Spalte12 int arx12[] = {400,380,370,380,400,410}; int ary56[] = {20,20,40,60,60,40}; int ary57[] = {60,60,80,100,100,80}; int ary58[] = {100,100,120,140,140,120}; int ary59[] = {140,140,160,180,180,160}; int ary60[] = {180,180,200,220,220,200}; //Spalte13 int arx13[] = {430,410,400,410,430,440}; int ary62[] = {40,40,60,80,80,60}; int ary63[] = {80,80,100,120,120,100}; int ary64[] = {120,120,140,160,160,140}; int ary65[] = {160,160,180,200,200,180}; //Spalte14 int arx14[] = {460,440,430,440,460,470}; int ary66[] = {20,20,40,60,60,40}; int ary67[] = {60,60,80,100,100,80}; int ary68[] = {100,100,120,140,140,120}; int ary69[] = {140,140,160,180,180,160}; int ary70[] = {180,180,200,220,220,200}; //Spalte15 int arx15[] = {490,470,460,470,490,500}; int ary72[] = {40,40,60,80,80,60}; int ary73[] = {80,80,100,120,120,100}; int ary74[] = {120,120,140,160,160,140}; int ary75[] = {160,160,180,200,200,180}; //Spalte16 int arx16[] = {520,500,490,500,520,530}; int ary76[] = {20,20,40,60,60,40}; int ary77[] = {60,60,80,100,100,80}; int ary78[] = {100,100,120,140,140,120}; int ary79[] = {140,140,160,180,180,160}; int ary80[] = {180,180,200,220,220,200}; //Spalte17 int arx17[] = {550,530,520,530,550,560}; int ary82[] = {40,40,60,80,80,60}; int ary83[] = {80,80,100,120,120,100}; int ary84[] = {120,120,140,160,160,140}; int ary85[] = {160,160,180,200,200,180}; //int arx4[] = {130,110,100,110,130,140}; //int ary4[] = {40,40,60,80,80,60}; //int arx5[] = {130,110,100,110,130,140}; //int ary5[] = {80,80,100,120,120,100}; g.drawPolygon(arx1,ary1,6); //Polygon1 /1 g.drawPolygon(arx1,ary2,6); //Polygon2 /1 g.drawPolygon(arx1,ary3,6); //Polygon3 /1 g.drawPolygon(arx1,ary4,6); //Polygon4 /1 g.drawPolygon(arx2,ary6,6); //Polygon1 /2 g.drawPolygon(arx2,ary7,6); //Polygon2 /2 g.drawPolygon(arx2,ary8,6); //Polygon3 /2 g.drawPolygon(arx2,ary9,6); //Polygon4 /2 g.drawPolygon(arx2,ary10,6); //Polygon5 /2 g.drawPolygon(arx3,ary12,6); //Polygon1 /3 g.drawPolygon(arx3,ary13,6); //Polygon2 /3 g.drawPolygon(arx3,ary14,6); //Polygon3 /3 g.drawPolygon(arx3,ary15,6); //Polygon4 /3 g.drawPolygon(arx4,ary16,6); //Polygon1 /4 g.drawPolygon(arx4,ary17,6); //Polygon2 /4 g.drawPolygon(arx4,ary18,6); //Polygon3 /4 g.drawPolygon(arx4,ary19,6); //Polygon4 /4 g.drawPolygon(arx4,ary20,6); //Polygon5 /4 g.drawPolygon(arx5,ary22,6); //Polygon1 /5 g.drawPolygon(arx5,ary23,6); //Polygon2 /5 g.drawPolygon(arx5,ary24,6); //Polygon3 /5 g.drawPolygon(arx5,ary25,6); //Polygon4 /5 g.drawPolygon(arx6,ary26,6); //Polygon1 /6 g.drawPolygon(arx6,ary27,6); //Polygon2 /6 g.drawPolygon(arx6,ary28,6); //Polygon3 /6 g.drawPolygon(arx6,ary29,6); //Polygon4 /6 g.drawPolygon(arx6,ary30,6); //Polygon5 /6 g.drawPolygon(arx7,ary32,6); //Polygon1 /7 g.drawPolygon(arx7,ary33,6); //Polygon2 /7 g.drawPolygon(arx7,ary34,6); //Polygon3 /7 g.drawPolygon(arx7,ary35,6); //Polygon4 /7 g.drawPolygon(arx8,ary36,6); //Polygon1 /8 g.drawPolygon(arx8,ary37,6); //Polygon2 /8 g.drawPolygon(arx8,ary38,6); //Polygon3 /8 g.drawPolygon(arx8,ary39,6); //Polygon4 /8 g.drawPolygon(arx8,ary40,6); //Polygon5 /8 g.drawPolygon(arx9,ary42,6); //Polygon1 /9 g.drawPolygon(arx9,ary43,6); //Polygon2 /9 g.drawPolygon(arx9,ary44,6); //Polygon3 /9 g.drawPolygon(arx9,ary45,6); //Polygon4 /9 g.drawPolygon(arx10,ary46,6); //Polygon1 /10 g.drawPolygon(arx10,ary47,6); //Polygon2 /10 g.drawPolygon(arx10,ary48,6); //Polygon3 /10 g.drawPolygon(arx10,ary49,6); //Polygon4 /10 g.drawPolygon(arx10,ary50,6); //Polygon5 /10 g.drawPolygon(arx11,ary52,6); //Polygon1 /11 g.drawPolygon(arx11,ary53,6); //Polygon2 /11 g.drawPolygon(arx11,ary54,6); //Polygon3 /11 g.drawPolygon(arx11,ary55,6); //Polygon4 /11 g.drawPolygon(arx12,ary56,6); //Polygon1 /12 g.drawPolygon(arx12,ary57,6); //Polygon2 /12 g.drawPolygon(arx12,ary58,6); //Polygon3 /12 g.drawPolygon(arx12,ary59,6); //Polygon4 /12 g.drawPolygon(arx12,ary60,6); //Polygon5 /12 g.drawPolygon(arx13,ary62,6); //Polygon1 /13 g.drawPolygon(arx13,ary63,6); //Polygon2 /13 g.drawPolygon(arx13,ary64,6); //Polygon3 /13 g.drawPolygon(arx13,ary65,6); //Polygon4 /13 g.drawPolygon(arx14,ary66,6); //Polygon1 /14 g.drawPolygon(arx14,ary67,6); //Polygon2 /14 g.drawPolygon(arx14,ary68,6); //Polygon3 /14 g.drawPolygon(arx14,ary69,6); //Polygon4 /14 g.drawPolygon(arx14,ary70,6); //Polygon5 /14 g.drawPolygon(arx15,ary72,6); //Polygon1 /15 g.drawPolygon(arx15,ary73,6); //Polygon2 /15 g.drawPolygon(arx15,ary74,6); //Polygon3 /15 g.drawPolygon(arx15,ary75,6); //Polygon4 /15 g.drawPolygon(arx16,ary76,6); //Polygon1 /16 g.drawPolygon(arx16,ary77,6); //Polygon2 /16 g.drawPolygon(arx16,ary78,6); //Polygon3 /16 g.drawPolygon(arx16,ary79,6); //Polygon4 /16 g.drawPolygon(arx16,ary80,6); //Polygon5 /16 g.drawPolygon(arx17,ary82,6); //Polygon1 /17 g.drawPolygon(arx17,ary83,6); //Polygon2 /17 g.drawPolygon(arx17,ary84,6); //Polygon3 /17 g.drawPolygon(arx17,ary85,6); //Polygon4 /17 if(a1==1) { g.fillPolygon(arx1,ary1,arx1.length); } } public void setX(int x) { this.x = x; repaint(); } } Zitieren
Frostmourne Geschrieben 11. Januar 2005 Autor Geschrieben 11. Januar 2005 ICh hab die beidem Progs nochmal überarbeitet doch sie tun immernoch nicht! DEr mouseListener funktioniert aber wenn ich die Leertaste drücke passiert nichts! import javax.swing.*; import java.awt.*; import java.awt.event.*; class GameGUI extends JFrame implements ActionListener, KeyListener, MouseListener { private Button b1; private Button b2; private Map m; private JTextField tsystem; private TextField tchat; private TextArea tchat2; private JPanel panel1; private JPanel panel2; private JPanel panel3; private JPanel haupt; public GameGUI() { //Titel des Fensters bestimmen!!! setTitle( "Game 1.0" ); //Anfangs größe des Fensters setSize( 600, 427 ); setResizable(false); setLocation(300,150); //setUndecorated(true); addMouseListener(this); addKeyListener(this); m = new Map(); // Konstruiere die Menüzeile !!! MenuBar M1 = new MenuBar(); Menu menu = new Menu( "Game" ); MenuItem Mitem2 = new MenuItem( "Optionen" ); Mitem2.addActionListener( this ); menu.add( Mitem2); MenuItem Mitem3 = new MenuItem( "Hilfe" ); Mitem3.addActionListener( this ); menu.add( Mitem3); MenuItem Mitem4 = new MenuItem( "Beenden" ); Mitem4.addActionListener( this ); menu.add( Mitem4); M1.add( menu ); setMenuBar( M1 ); haupt = new JPanel(null); panel1 = new JPanel(new GridLayout()); panel1.setBounds(0,0,600,250); //von links, von oben ,Länge, Breite panel2 = new JPanel(new FlowLayout()); panel2.setBounds(0,250,600,150); //von links, von oben ,Länge, Breite tsystem = new JTextField("",41); tsystem.setFont(new Font("Arial", 1, 15)); tsystem.setHorizontalAlignment(SwingConstants.CENTER); tsystem.setEditable(false); tchat = new TextField("",15); tchat.setFont(new Font("Arial", 3, 10)); tchat2 = new TextArea("", 4, 50); tchat2.setFont(new Font("Arial", 3, 10)); tchat2.setEditable(false); b1= new Button ("Runde beenden"); b1.addActionListener(this); b1.setBackground(Color.lightGray); b2= new Button ("Nachricht senden"); b2.setActionCommand("Senden"); b2.addActionListener(this); b2.setBackground(Color.lightGray); panel1.add(m); panel2.add(tsystem); panel2.add(tchat2); panel2.add(tchat); panel2.add(b2); panel2.add(b1); haupt.add(panel1); haupt.add(panel2); haupt.setVisible(true); panel1.setVisible(true); panel2.setVisible(true); Container einContainer = getContentPane(); einContainer.add(haupt); // Das Fenster mit X schließen !!! setDefaultCloseOperation(EXIT_ON_CLOSE); } public void actionPerformed( ActionEvent evt ) { String command = evt.getActionCommand(); { if (command.equals("Beenden")) { System.exit(0); } if (command.equals("Senden")) { String a = tchat.getText(); tchat2.setText(tchat2.getText() + "\n" + a); } } } public void keyPressed(KeyEvent event) { if(event.getKeyCode() == KeyEvent.VK_SPACE ) { System.out.println("test!" ); } } public void keyReleased(KeyEvent event) { } public void keyTyped(KeyEvent event) { } public void mouseClicked(MouseEvent mvt) { } public void mouseEntered(MouseEvent mvt) { } public void mouseExited(MouseEvent mvt) { } public void mousePressed(MouseEvent mvt) { } public void mouseReleased(MouseEvent mvt) { if(mvt.getButton()==1) { System.out.println("test" ); } if(mvt.getButton()==3) { } } public static void main( String[]args ) { GameGUI gg = new GameGUI(); gg.start(); } public void start() { setVisible(true); } } Zitieren
Frostmourne Geschrieben 11. Januar 2005 Autor Geschrieben 11. Januar 2005 import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; class Map extends JPanel { private GameGUI gg; private int x=0; private int a1=0; public void paintComponent(Graphics g) { super.paintComponent(g); //Spalte1 int arx1[] = {70,50,40,50,70,80};// 2te unt 4te Zahl ändern um linke Seite abzuflachen rechte Seite= 1te und 5te int ary1[] = {40,40,60,80,80,60}; int ary2[] = {80,80,100,120,120,100}; int ary3[] = {120,120,140,160,160,140}; int ary4[] = {160,160,180,200,200,180}; //Spalte2 int arx2[] = {100,80,70,80,100,110}; int ary6[] = {20,20,40,60,60,40}; int ary7[] = {60,60,80,100,100,80}; int ary8[] = {100,100,120,140,140,120}; int ary9[] = {140,140,160,180,180,160}; int ary10[] = {180,180,200,220,220,200}; //Spalte3 int arx3[] = {130,110,100,110,130,140}; int ary12[] = {40,40,60,80,80,60}; int ary13[] = {80,80,100,120,120,100}; int ary14[] = {120,120,140,160,160,140}; int ary15[] = {160,160,180,200,200,180}; //Spalte4 int arx4[] = {160,140,130,140,160,170}; int ary16[] = {20,20,40,60,60,40}; int ary17[] = {60,60,80,100,100,80}; int ary18[] = {100,100,120,140,140,120}; int ary19[] = {140,140,160,180,180,160}; int ary20[] = {180,180,200,220,220,200}; //Spalte5 int arx5[] = {190,170,160,170,190,200}; int ary22[] = {40,40,60,80,80,60}; int ary23[] = {80,80,100,120,120,100}; int ary24[] = {120,120,140,160,160,140}; int ary25[] = {160,160,180,200,200,180}; //Spalte6 int arx6[] = {220,200,190,200,220,230}; int ary26[] = {20,20,40,60,60,40}; int ary27[] = {60,60,80,100,100,80}; int ary28[] = {100,100,120,140,140,120}; int ary29[] = {140,140,160,180,180,160}; int ary30[] = {180,180,200,220,220,200}; //Spalte7 int arx7[] = {250,230,220,230,250,260}; int ary32[] = {40,40,60,80,80,60}; int ary33[] = {80,80,100,120,120,100}; int ary34[] = {120,120,140,160,160,140}; int ary35[] = {160,160,180,200,200,180}; //Spalte8 int arx8[] = {280,260,250,260,280,290}; int ary36[] = {20,20,40,60,60,40}; int ary37[] = {60,60,80,100,100,80}; int ary38[] = {100,100,120,140,140,120}; int ary39[] = {140,140,160,180,180,160}; int ary40[] = {180,180,200,220,220,200}; //Spalte9 int arx9[] = {310,290,280,290,310,320}; int ary42[] = {40,40,60,80,80,60}; int ary43[] = {80,80,100,120,120,100}; int ary44[] = {120,120,140,160,160,140}; int ary45[] = {160,160,180,200,200,180}; //Spalte10 int arx10[] = {340,320,310,320,340,350}; int ary46[] = {20,20,40,60,60,40}; int ary47[] = {60,60,80,100,100,80}; int ary48[] = {100,100,120,140,140,120}; int ary49[] = {140,140,160,180,180,160}; int ary50[] = {180,180,200,220,220,200}; //Spalte11 int arx11[] = {370,350,340,350,370,380}; int ary52[] = {40,40,60,80,80,60}; int ary53[] = {80,80,100,120,120,100}; int ary54[] = {120,120,140,160,160,140}; int ary55[] = {160,160,180,200,200,180}; //Spalte12 int arx12[] = {400,380,370,380,400,410}; int ary56[] = {20,20,40,60,60,40}; int ary57[] = {60,60,80,100,100,80}; int ary58[] = {100,100,120,140,140,120}; int ary59[] = {140,140,160,180,180,160}; int ary60[] = {180,180,200,220,220,200}; //Spalte13 int arx13[] = {430,410,400,410,430,440}; int ary62[] = {40,40,60,80,80,60}; int ary63[] = {80,80,100,120,120,100}; int ary64[] = {120,120,140,160,160,140}; int ary65[] = {160,160,180,200,200,180}; //Spalte14 int arx14[] = {460,440,430,440,460,470}; int ary66[] = {20,20,40,60,60,40}; int ary67[] = {60,60,80,100,100,80}; int ary68[] = {100,100,120,140,140,120}; int ary69[] = {140,140,160,180,180,160}; int ary70[] = {180,180,200,220,220,200}; //Spalte15 int arx15[] = {490,470,460,470,490,500}; int ary72[] = {40,40,60,80,80,60}; int ary73[] = {80,80,100,120,120,100}; int ary74[] = {120,120,140,160,160,140}; int ary75[] = {160,160,180,200,200,180}; //Spalte16 int arx16[] = {520,500,490,500,520,530}; int ary76[] = {20,20,40,60,60,40}; int ary77[] = {60,60,80,100,100,80}; int ary78[] = {100,100,120,140,140,120}; int ary79[] = {140,140,160,180,180,160}; int ary80[] = {180,180,200,220,220,200}; //Spalte17 int arx17[] = {550,530,520,530,550,560}; int ary82[] = {40,40,60,80,80,60}; int ary83[] = {80,80,100,120,120,100}; int ary84[] = {120,120,140,160,160,140}; int ary85[] = {160,160,180,200,200,180}; //int arx4[] = {130,110,100,110,130,140}; //int ary4[] = {40,40,60,80,80,60}; //int arx5[] = {130,110,100,110,130,140}; //int ary5[] = {80,80,100,120,120,100}; g.drawPolygon(arx1,ary1,6); //Polygon1 /1 g.drawPolygon(arx1,ary2,6); //Polygon2 /1 g.drawPolygon(arx1,ary3,6); //Polygon3 /1 g.drawPolygon(arx1,ary4,6); //Polygon4 /1 g.drawPolygon(arx2,ary6,6); //Polygon1 /2 g.drawPolygon(arx2,ary7,6); //Polygon2 /2 g.drawPolygon(arx2,ary8,6); //Polygon3 /2 g.drawPolygon(arx2,ary9,6); //Polygon4 /2 g.drawPolygon(arx2,ary10,6); //Polygon5 /2 g.drawPolygon(arx3,ary12,6); //Polygon1 /3 g.drawPolygon(arx3,ary13,6); //Polygon2 /3 g.drawPolygon(arx3,ary14,6); //Polygon3 /3 g.drawPolygon(arx3,ary15,6); //Polygon4 /3 g.drawPolygon(arx4,ary16,6); //Polygon1 /4 g.drawPolygon(arx4,ary17,6); //Polygon2 /4 g.drawPolygon(arx4,ary18,6); //Polygon3 /4 g.drawPolygon(arx4,ary19,6); //Polygon4 /4 g.drawPolygon(arx4,ary20,6); //Polygon5 /4 g.drawPolygon(arx5,ary22,6); //Polygon1 /5 g.drawPolygon(arx5,ary23,6); //Polygon2 /5 g.drawPolygon(arx5,ary24,6); //Polygon3 /5 g.drawPolygon(arx5,ary25,6); //Polygon4 /5 g.drawPolygon(arx6,ary26,6); //Polygon1 /6 g.drawPolygon(arx6,ary27,6); //Polygon2 /6 g.drawPolygon(arx6,ary28,6); //Polygon3 /6 g.drawPolygon(arx6,ary29,6); //Polygon4 /6 g.drawPolygon(arx6,ary30,6); //Polygon5 /6 g.drawPolygon(arx7,ary32,6); //Polygon1 /7 g.drawPolygon(arx7,ary33,6); //Polygon2 /7 g.drawPolygon(arx7,ary34,6); //Polygon3 /7 g.drawPolygon(arx7,ary35,6); //Polygon4 /7 g.drawPolygon(arx8,ary36,6); //Polygon1 /8 g.drawPolygon(arx8,ary37,6); //Polygon2 /8 g.drawPolygon(arx8,ary38,6); //Polygon3 /8 g.drawPolygon(arx8,ary39,6); //Polygon4 /8 g.drawPolygon(arx8,ary40,6); //Polygon5 /8 g.drawPolygon(arx9,ary42,6); //Polygon1 /9 g.drawPolygon(arx9,ary43,6); //Polygon2 /9 g.drawPolygon(arx9,ary44,6); //Polygon3 /9 g.drawPolygon(arx9,ary45,6); //Polygon4 /9 g.drawPolygon(arx10,ary46,6); //Polygon1 /10 g.drawPolygon(arx10,ary47,6); //Polygon2 /10 g.drawPolygon(arx10,ary48,6); //Polygon3 /10 g.drawPolygon(arx10,ary49,6); //Polygon4 /10 g.drawPolygon(arx10,ary50,6); //Polygon5 /10 g.drawPolygon(arx11,ary52,6); //Polygon1 /11 g.drawPolygon(arx11,ary53,6); //Polygon2 /11 g.drawPolygon(arx11,ary54,6); //Polygon3 /11 g.drawPolygon(arx11,ary55,6); //Polygon4 /11 g.drawPolygon(arx12,ary56,6); //Polygon1 /12 g.drawPolygon(arx12,ary57,6); //Polygon2 /12 g.drawPolygon(arx12,ary58,6); //Polygon3 /12 g.drawPolygon(arx12,ary59,6); //Polygon4 /12 g.drawPolygon(arx12,ary60,6); //Polygon5 /12 g.drawPolygon(arx13,ary62,6); //Polygon1 /13 g.drawPolygon(arx13,ary63,6); //Polygon2 /13 g.drawPolygon(arx13,ary64,6); //Polygon3 /13 g.drawPolygon(arx13,ary65,6); //Polygon4 /13 g.drawPolygon(arx14,ary66,6); //Polygon1 /14 g.drawPolygon(arx14,ary67,6); //Polygon2 /14 g.drawPolygon(arx14,ary68,6); //Polygon3 /14 g.drawPolygon(arx14,ary69,6); //Polygon4 /14 g.drawPolygon(arx14,ary70,6); //Polygon5 /14 g.drawPolygon(arx15,ary72,6); //Polygon1 /15 g.drawPolygon(arx15,ary73,6); //Polygon2 /15 g.drawPolygon(arx15,ary74,6); //Polygon3 /15 g.drawPolygon(arx15,ary75,6); //Polygon4 /15 g.drawPolygon(arx16,ary76,6); //Polygon1 /16 g.drawPolygon(arx16,ary77,6); //Polygon2 /16 g.drawPolygon(arx16,ary78,6); //Polygon3 /16 g.drawPolygon(arx16,ary79,6); //Polygon4 /16 g.drawPolygon(arx16,ary80,6); //Polygon5 /16 g.drawPolygon(arx17,ary82,6); //Polygon1 /17 g.drawPolygon(arx17,ary83,6); //Polygon2 /17 g.drawPolygon(arx17,ary84,6); //Polygon3 /17 g.drawPolygon(arx17,ary85,6); //Polygon4 /17 if(a1==1) { g.fillPolygon(arx1,ary1,arx1.length); } } public void setX(int x) { this.x = x; repaint(); } } Zitieren
geloescht_Newlukai Geschrieben 11. Januar 2005 Geschrieben 11. Januar 2005 Versuch's doch mal mit einer der beiden anderen key-Funktionen. Oder imeplementier' mal alle 3 in dieser Weise public void keyPressed() { [INDENT]System.out.println("Pressed");[/INDENT] } und nimm Dir die passende... Zitieren
BenjieAul Geschrieben 11. Januar 2005 Geschrieben 11. Januar 2005 Ist logisch das es nicht funktioniert. Du musst das ganze ja auch zuweisen! Musst das ganze ja auch etwas wie, ka, z.B. einem Textarea zuweisen. Zitieren
geloescht_Newlukai Geschrieben 11. Januar 2005 Geschrieben 11. Januar 2005 Ist logisch das es nicht funktioniert. Du musst das ganze ja auch zuweisen! Musst das ganze ja auch etwas wie, ka, z.B. einem Textarea zuweisen. Hm? Es wird doch nur eine Konsolenausgabe gemacht. Die müßte an sich angezeigt werden. Oder was meinst Du genau? Jedenfalls würde ich auch mal statt der Verzwigung einfach generell mal testen, ob der Kontrollfluß in dieser Operation ankommt. Zitieren
BenjieAul Geschrieben 11. Januar 2005 Geschrieben 11. Januar 2005 HAt mit der Konsolenausgabe ja nix zu tun. Wenn der da irgendwie so einen KeyListener ahben will, soll er mal im Forum danach suchen, hatte so nhen ähnliches Problem und das musste man anders lösen. Zitieren
Frostmourne Geschrieben 11. Januar 2005 Autor Geschrieben 11. Januar 2005 Der KeyListener ist ja zugewiesen und zwar auf die JPanel, das is ja mein Problem wenn ich den KeyListener auf das Textarea mache dann tut der!! Aber auch nur wenn der Focus auf dem Textarea oder Textfeld ist das heisst wenn ich rein geklickt habe aber ich möchte das er funktioniert wenn ich auf den JPanels bin! Zitieren
geloescht_Newlukai Geschrieben 12. Januar 2005 Geschrieben 12. Januar 2005 Der KeyListener ist ja zugewiesen und zwar auf die JPanel, das is ja mein Problem wenn ich den KeyListener auf das Textarea mache dann tut der!! Aber auch nur wenn der Focus auf dem Textarea oder Textfeld ist das heisst wenn ich rein geklickt habe aber ich möchte das er funktioniert wenn ich auf den JPanels bin! Ich hab' den Code jetzt ein paar Mal durchgesehen und muß BenjieAul recht geben. Du weist nur einmal einen KeyListener zu und zwar dem Objekt der Klasse GameGUI und sonst nirgends. Weis ihn doch mal dem JPanel haupt zu?!? Zitieren
Frostmourne Geschrieben 12. Januar 2005 Autor Geschrieben 12. Januar 2005 Hab ich schon gemacht der war schon auf allen Panels das tat trotzdem nicht ! Zitieren
DerFreddy Geschrieben 12. Januar 2005 Geschrieben 12. Januar 2005 Also wenn man den JPanel haupt nicht added funktioniert es. Zitieren
BenjieAul Geschrieben 17. Januar 2005 Geschrieben 17. Januar 2005 Also, ich habe mich nochmal mit deinem Code auseinander gesetzt. ISt eigentlich ganz Simpel. Du hast nur deinem Fenster einen KeyListener zugewiesen, nicht aber deinem Panel!!! Du musst deinem Panel zuweisen, sonst wird es nicht funktionieren. Zitieren
geloescht_Newlukai Geschrieben 17. Januar 2005 Geschrieben 17. Januar 2005 Also, ich habe mich nochmal mit deinem Code auseinander gesetzt. ISt eigentlich ganz Simpel. Du hast nur deinem Fenster einen KeyListener zugewiesen, nicht aber deinem Panel!!! Du musst deinem Panel zuweisen, sonst wird es nicht funktionieren. Sag' ich doch Zitieren
Empfohlene Beiträge
Dein Kommentar
Du kannst jetzt schreiben und Dich später registrieren. Wenn Du ein Konto hast, melde Dich jetzt an, um unter Deinem Benutzernamen zu schreiben.