ERLEDIGT
NEIN
NEIN
ANTWORTEN
6
6
ZUGRIFFE
660
660
EMPFEHLEN
-
Hallo,
zu aller erst : Ich bin kein Profi.
Habe mit Eclipse und dem Plugin WindowBuilder (bitte nicht schimpfen) ein Design gebaut.
Das wird mir auch Prima in diesen Testfenster angezeigt, aber wenn ich das Applet compiliere zeigt er mir das Jpanel komplett leer an.
Hier der code: (Viele Imports sind überflüssig)
Code java:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
package HSFulda; import java.applet.*; import java.awt.*; import javax.swing.JApplet; import net.sourceforge.jFuzzyLogic.FIS; import javax.swing.JPanel; import java.awt.Container; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Image; import javax.swing.JLabel; import java.awt.Font; import java.awt.Insets; import javax.swing.JSlider; import javax.swing.SwingConstants; import javax.swing.JButton; import javax.swing.event.ChangeListener; import javax.swing.event.ChangeEvent; import javax.swing.ImageIcon; import javax.swing.border.LineBorder; import javax.swing.DebugGraphics; public class Helikoptergui extends JApplet{ /** * */ static JSlider WindvonLinks = new JSlider(); static JSlider WindvonRechts = new JSlider(); static JSlider HelikopterHoehe = new JSlider(); static JPanel Feld = new JPanel(); public void init(){ setSize(800,600); GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[]{33, 84, 32, 500, 33, 98, 20, 0}; gridBagLayout.rowHeights = new int[]{24, 15, 27, 450, 48, 18, 0}; gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, Double.MIN_VALUE}; gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 1.0, 1.0, 0.0, Double.MIN_VALUE}; getContentPane().setLayout(gridBagLayout); JLabel lblHelikopter = new JLabel(" Helikopter Landung"); lblHelikopter.setFont(new Font("Tahoma", Font.PLAIN, 23)); GridBagConstraints gbc_lblHelikopter = new GridBagConstraints(); gbc_lblHelikopter.anchor = GridBagConstraints.WEST; gbc_lblHelikopter.insets = new Insets(0, 0, 5, 5); gbc_lblHelikopter.gridx = 3; gbc_lblHelikopter.gridy = 0; getContentPane().add(lblHelikopter, gbc_lblHelikopter); JLabel lblBylabel = new JLabel("by me"); GridBagConstraints gbc_lblBylabel = new GridBagConstraints(); gbc_lblBylabel.insets = new Insets(0, 0, 5, 5); gbc_lblBylabel.gridx = 3; gbc_lblBylabel.gridy = 1; getContentPane().add(lblBylabel, gbc_lblBylabel); JLabel lblWindVonLinks = new JLabel("Wind von Links"); GridBagConstraints gbc_lblWindVonLinks = new GridBagConstraints(); gbc_lblWindVonLinks.insets = new Insets(0, 0, 5, 5); gbc_lblWindVonLinks.gridx = 1; gbc_lblWindVonLinks.gridy = 2; getContentPane().add(lblWindVonLinks, gbc_lblWindVonLinks); JLabel lblWindVonRechts = new JLabel("Wind von Rechts"); GridBagConstraints gbc_lblWindVonRechts = new GridBagConstraints(); gbc_lblWindVonRechts.insets = new Insets(0, 0, 5, 5); gbc_lblWindVonRechts.gridx = 5; gbc_lblWindVonRechts.gridy = 2; getContentPane().add(lblWindVonRechts, gbc_lblWindVonRechts); WindvonLinks.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { checkWind(false); } }); WindvonLinks.setMajorTickSpacing(10); WindvonLinks.setToolTipText("Wind kann nur von einer Richtung kommen"); WindvonLinks.setPaintLabels(true); WindvonLinks.setPaintTicks(true); WindvonLinks.setValue(100); WindvonLinks.setMaximum(200); WindvonLinks.setSnapToTicks(true); WindvonLinks.setOrientation(SwingConstants.VERTICAL); GridBagConstraints gbc_WindvonLinks = new GridBagConstraints(); gbc_WindvonLinks.fill = GridBagConstraints.BOTH; gbc_WindvonLinks.insets = new Insets(0, 0, 5, 5); gbc_WindvonLinks.gridx = 1; gbc_WindvonLinks.gridy = 3; getContentPane().add(WindvonLinks, gbc_WindvonLinks); WindvonRechts.setValue(0); WindvonRechts.setToolTipText("Wind kann nur von einer Richtung kommen"); WindvonRechts.setMajorTickSpacing(10); WindvonRechts.setMaximum(200); WindvonRechts.setOrientation(SwingConstants.VERTICAL); WindvonRechts.setSnapToTicks(true); WindvonRechts.setPaintTicks(true); WindvonRechts.setPaintLabels(true); GridBagConstraints gbc_WindvonRechts = new GridBagConstraints(); gbc_WindvonRechts.fill = GridBagConstraints.BOTH; gbc_WindvonRechts.insets = new Insets(0, 0, 5, 5); gbc_WindvonRechts.gridx = 5; gbc_WindvonRechts.gridy = 3; getContentPane().add(WindvonRechts, gbc_WindvonRechts); WindvonRechts.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { checkWind(true); } }); HelikopterHoehe.setValue(450); HelikopterHoehe.setMajorTickSpacing(50); HelikopterHoehe.setMaximum(450); HelikopterHoehe.setSnapToTicks(true); HelikopterHoehe.setPaintTicks(true); HelikopterHoehe.setPaintLabels(true); GridBagConstraints gbc_HelikopterHoehe = new GridBagConstraints(); gbc_HelikopterHoehe.fill = GridBagConstraints.BOTH; gbc_HelikopterHoehe.insets = new Insets(0, 0, 5, 5); gbc_HelikopterHoehe.gridx = 3; gbc_HelikopterHoehe.gridy = 4; getContentPane().add(HelikopterHoehe, gbc_HelikopterHoehe); JButton btnStart = new JButton("START!"); GridBagConstraints gbc_btnStart = new GridBagConstraints(); gbc_btnStart.insets = new Insets(0, 0, 5, 5); gbc_btnStart.gridx = 5; gbc_btnStart.gridy = 4; getContentPane().add(btnStart, gbc_btnStart); JLabel lblHelikopterHoehe = new JLabel("Helikopter Hoehe"); GridBagConstraints gbc_lblHelikopterHoehe = new GridBagConstraints(); gbc_lblHelikopterHoehe.insets = new Insets(0, 0, 0, 5); gbc_lblHelikopterHoehe.gridx = 3; gbc_lblHelikopterHoehe.gridy = 5; getContentPane().add(lblHelikopterHoehe, gbc_lblHelikopterHoehe); GridBagConstraints gbc_Feld = new GridBagConstraints(); gbc_Feld.fill = GridBagConstraints.BOTH; gbc_Feld.insets = new Insets(0, 0, 5, 5); gbc_Feld.gridx = 3; gbc_Feld.gridy = 3; JPanel Feld = new JPanel(); Feld.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); Feld.setBorder(new LineBorder(new Color(0, 0, 0), 2, true)); Feld.setLayout(null); Feld.setBackground(new Color(153, 255, 255)); getContentPane().add(Feld, gbc_Feld); JLabel Helikopter = new JLabel(""); Helikopter.setSize(111, 46); Helikopter.setLocation(183, 0); Helikopter.setIcon(new ImageIcon("PFAD ZUM BILD")); Feld.add(Helikopter); JLabel bg = new JLabel(""); bg.setIcon(new ImageIcon("PFAD ZUM BILD")); bg.setBounds(0, 346, 492, 100); Feld.add(bg); } public void checkWind(boolean i){ if(i){WindvonLinks.setValue(0);} else{WindvonRechts.setValue(0); } } public void paint(Graphics g){ } }
Ich bin mir sicher, dass jemand, der sich mit Applets auskennt sofort den Fehler sieht. Aber mir bleibt das Licht der Erkenntnis seit 2 Tagen aus.
lG
-
17.12.11 22:13 #2
- Registriert seit
- Jun 2009
- Beiträge
- 870
Hi und willkommen im Forum!
zuerst: wenn du paint() aufrufst, solltest du darin super.paint() aufrufen. Außerdem solltest du die Methode paint() in Swing (wo JPanel, JApplet, ... dazugehören) nicht benutzen und nicht überschreiben.
Treten außerdem noch irgend welche Fehlermeldungen auf? (Exceptions?)
(PS: dein Code-Posting und die Fehlerbeschreibung sind wirklich hilfreich!)Code bitte so einfügen: [java]System.out.println("Hallo");[/java] (Analog für andere Programmiersprachen)
hilfreich zu Java: Really Big Index, Java ist auch eine Insel Band 1 und Band 2.Code java:1
System.out.println("Hallo");
___________
Ubuntu Bug #1: Microsoft has a majority market share
Casecon: Projekt leiser Käse
-
Hallo,
erstmal danke für die Antwort und für das P.S.
Habe alles ausprobiert. Mit oder ohne paint() und bestimmt 10 mal. Alles soll am Ende ein JApplet werden.
Keine Exception wird geworfen. Ich bekomme einfach keinen Inhalt in mein Jpanel.
Ich benutze auf das gesamte Layout GridBagLayout und im Panel das Null Layout um meine Objekte frei zu bewegen.
Kann es sein, dass mein Jpanel von irgendetwas überschrieben wird, oder das irgendetwas sich auf mein Panel legt? Habe Panel und Jpanel probiert bei beiden derselbe weise Fleck. Noch nicht einmal die Hintergrundfarbe wird gesetzt.
Nur noch mal verständlicher. So sollte es aussehen :
http://dl.dropbox.com/u/6713688/SoftComputing/Soll.jpg
und so sieht es aus:
http://dl.dropbox.com/u/6713688/SoftComputing/ist.jpg
Ich komme seit einigen Tagen jetzt schon nicht mehr weiter und würde ungern aufgeben
Hier nochmal ein bisschen abgewandelter Code, wo aber dasselbe Problem auftritt:
Code java:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
package HSFulda; import java.applet.*; import java.awt.*; import javax.swing.JApplet; import net.sourceforge.jFuzzyLogic.FIS; import javax.swing.JPanel; import java.awt.Container; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Image; import javax.swing.JLabel; import java.awt.Font; import java.awt.Insets; import javax.swing.JFrame; import javax.swing.JSlider; import javax.swing.SwingConstants; import javax.swing.JButton; import javax.swing.event.ChangeListener; import javax.swing.event.ChangeEvent; import javax.swing.ImageIcon; import javax.swing.border.LineBorder; import javax.swing.DebugGraphics; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class Helikoptergui extends JApplet{ public Helikoptergui() { } /** * */ static JPanel Feld = new JPanel(); static JSlider WindvonLinks = new JSlider(); static JSlider WindvonRechts = new JSlider(); static JSlider HelikopterHoehe = new JSlider(); static JLabel Helikopter = new JLabel(""); static GridBagConstraints gbc_Feld = new GridBagConstraints(); public void init(){ setSize(800,600); GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[]{33, 84, 32, 500, 33, 98, 20, 0}; gridBagLayout.rowHeights = new int[]{24, 15, 27, 450, 48, 18, 0}; gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE}; gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE}; getContentPane().setLayout(gridBagLayout); JLabel lblHelikopter = new JLabel(" Helikopter Landung"); lblHelikopter.setFont(new Font("Tahoma", Font.PLAIN, 23)); GridBagConstraints gbc_lblHelikopter = new GridBagConstraints(); gbc_lblHelikopter.anchor = GridBagConstraints.WEST; gbc_lblHelikopter.insets = new Insets(0, 0, 5, 5); gbc_lblHelikopter.gridx = 3; gbc_lblHelikopter.gridy = 0; getContentPane().add(lblHelikopter, gbc_lblHelikopter); JLabel lblWindVonLinks = new JLabel("Wind von Links"); GridBagConstraints gbc_lblWindVonLinks = new GridBagConstraints(); gbc_lblWindVonLinks.insets = new Insets(0, 0, 5, 5); gbc_lblWindVonLinks.gridx = 1; gbc_lblWindVonLinks.gridy = 2; getContentPane().add(lblWindVonLinks, gbc_lblWindVonLinks); JLabel lblWindVonRechts = new JLabel("Wind von Rechts"); GridBagConstraints gbc_lblWindVonRechts = new GridBagConstraints(); gbc_lblWindVonRechts.insets = new Insets(0, 0, 5, 5); gbc_lblWindVonRechts.gridx = 5; gbc_lblWindVonRechts.gridy = 2; getContentPane().add(lblWindVonRechts, gbc_lblWindVonRechts); WindvonLinks.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { checkWind(false); } }); WindvonLinks.setMajorTickSpacing(10); WindvonLinks.setToolTipText("Wind kann nur von einer Richtung kommen"); WindvonLinks.setPaintLabels(true); WindvonLinks.setPaintTicks(true); WindvonLinks.setValue(100); WindvonLinks.setMaximum(200); WindvonLinks.setSnapToTicks(true); WindvonLinks.setOrientation(SwingConstants.VERTICAL); GridBagConstraints gbc_WindvonLinks = new GridBagConstraints(); gbc_WindvonLinks.fill = GridBagConstraints.BOTH; gbc_WindvonLinks.insets = new Insets(0, 0, 5, 5); gbc_WindvonLinks.gridx = 1; gbc_WindvonLinks.gridy = 3; getContentPane().add(WindvonLinks, gbc_WindvonLinks); WindvonRechts.setValue(0); WindvonRechts.setToolTipText("Wind kann nur von einer Richtung kommen"); WindvonRechts.setMajorTickSpacing(10); WindvonRechts.setMaximum(200); WindvonRechts.setOrientation(SwingConstants.VERTICAL); WindvonRechts.setSnapToTicks(true); WindvonRechts.setPaintTicks(true); WindvonRechts.setPaintLabels(true); GridBagConstraints gbc_WindvonRechts = new GridBagConstraints(); gbc_WindvonRechts.fill = GridBagConstraints.BOTH; gbc_WindvonRechts.insets = new Insets(0, 0, 5, 5); gbc_WindvonRechts.gridx = 5; gbc_WindvonRechts.gridy = 3; getContentPane().add(WindvonRechts, gbc_WindvonRechts); WindvonRechts.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { checkWind(true); } }); HelikopterHoehe.setValue(450); HelikopterHoehe.setMajorTickSpacing(50); HelikopterHoehe.setMaximum(450); HelikopterHoehe.setSnapToTicks(true); HelikopterHoehe.setPaintTicks(true); HelikopterHoehe.setPaintLabels(true); GridBagConstraints gbc_HelikopterHoehe = new GridBagConstraints(); gbc_HelikopterHoehe.fill = GridBagConstraints.BOTH; gbc_HelikopterHoehe.insets = new Insets(0, 0, 5, 5); gbc_HelikopterHoehe.gridx = 3; gbc_HelikopterHoehe.gridy = 4; getContentPane().add(HelikopterHoehe, gbc_HelikopterHoehe); JButton btnStart = new JButton("START!"); btnStart.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent arg0) { start(); } }); GridBagConstraints gbc_btnStart = new GridBagConstraints(); gbc_btnStart.insets = new Insets(0, 0, 5, 5); gbc_btnStart.gridx = 5; gbc_btnStart.gridy = 4; getContentPane().add(btnStart, gbc_btnStart); JLabel lblHelikopterHoehe = new JLabel("Helikopter Hoehe"); GridBagConstraints gbc_lblHelikopterHoehe = new GridBagConstraints(); gbc_lblHelikopterHoehe.insets = new Insets(0, 0, 0, 5); gbc_lblHelikopterHoehe.gridx = 3; gbc_lblHelikopterHoehe.gridy = 5; getContentPane().add(lblHelikopterHoehe, gbc_lblHelikopterHoehe); gbc_Feld.fill = GridBagConstraints.BOTH; gbc_Feld.insets = new Insets(0, 0, 5, 5); gbc_Feld.gridx = 3; gbc_Feld.gridy = 3; Feld.setSize(new Dimension(500, 450)); Feld.setMaximumSize(new Dimension(500, 450)); Feld.setBackground(new Color(135, 206, 235)); Feld.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); Feld.setBorder(new LineBorder(new Color(0, 0, 0), 2, true)); Feld.setLayout(null); Helikopter.setBounds(183, 0, 111, 46); Helikopter.setIcon(new ImageIcon(Helikoptergui.class.getResource( "Heli.png"))); Feld.add(Helikopter); JLabel bg = new JLabel(""); bg.setBounds(0, 346, 492, 100); bg.setIcon(new ImageIcon(Helikoptergui.class.getResource("bg.png"))); Feld.add(bg); getContentPane().add(Feld, gbc_Feld); } public void checkWind(boolean i){ if(i){WindvonLinks.setValue(0);} else{WindvonRechts.setValue(0); } } public void start(){ Helikopter.setBounds(HelikopterHoehe.getValue(),0,111, 46); Feld.add(Helikopter); getContentPane().add(Feld, gbc_Feld); } }
-
Hallo, ich konnte den "abgewandelten Code" in meiner Umgebung starten und erhielt zuerst zwei NullPointerExceptions wegen den nicht vorhandenen Heli.png und bg.pgn. Nachdem ich das korrigiert habe, wurde sowohl das Bild im Heli.pgn wie auch der Hintergrund in bg.png im Applet richtig dargestellt. Es liegt also kaum an den Panels. Bist Du sicher, dass beide Dateien Heli.pgn und bg.pgn im gleichen Verzeichnis wie das File Helikoptergui.class liegen?
-
Hallo,
erstmal vielen dank für deine Antwort.
Ich bekomme das Programm nicht zum laufen. Die Heli.png und bg.png liegen im selben Verzeichnis und ich bekomme auch keine Exception.
In was für einer Umgebung hast du es denn zum laufen gebracht? Ich benutze Eclipse.
-
ich benutze java sdk 7.0 und eclipse indigo.
-
Ich komme nicht mehr weiter. Könntest du mir sagen, was du genau geändert hast, oder mir den Code senden. Ich weiß nicht, was bei mir falsch sein soll.
okay. wow
meine Eclipse Umgebaung war irgendwie total verammelt.
Habe Eclipse neu installiert und es lief mit demselben Code. Dennoch vielen Dank. Ich habe bestimmt noch weitere Fragen.
lG zipfelQGeändert von sheel (04.01.12 um 05:16 Uhr) Grund: Doppel
Ähnliche Themen
-
ScrollPane bleibt leer
Von dodlhuat im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 3Letzter Beitrag: 03.08.09, 19:48 -
Formularemail bleibt leer
Von schiwunja im Forum PHPAntworten: 6Letzter Beitrag: 27.10.07, 19:48 -
Array ist und bleibt leer
Von Braver Willy im Forum PHPAntworten: 5Letzter Beitrag: 17.07.07, 19:28 -
JTable bleibt leer :(
Von Davtorik im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 4Letzter Beitrag: 13.05.06, 22:10 -
JFrame bleibt leer
Von kekrops im Forum JavaAntworten: 3Letzter Beitrag: 12.10.05, 22:35





Zitieren
Login





