F
fdyöklgj
Gast
Sollte ein Listenvisualisierungstool werden.
Die Knoten sollen auf einem Panel angezeigt werden, wenn man in der Combobox "Knoten einfügen" wählt und aud den "Ausführen" Button klickt
Der Quellcode und die Fehlermeldung. Kann nichts damit anfangen
Fehlermeldung:
Die Knoten sollen auf einem Panel angezeigt werden, wenn man in der Combobox "Knoten einfügen" wählt und aud den "Ausführen" Button klickt
Der Quellcode und die Fehlermeldung. Kann nichts damit anfangen
Java:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.Graphics;
import java . lang . * ;
/**
*
* Beschreibung
*
* @version 1.0 vom 18.06.2012
* @author
*/
public class frame extends Frame {
// Anfang Attribute
private JLabel header = new JLabel();
private JButton beenden_Button = new JButton();
private JPanel jPanel1 = new JPanel(null, true);
private JComboBox aktionen_Combo = new JComboBox();
private JButton ausfuehren_Button = new JButton();
private JLabel aktionen_Label = new JLabel();
final JPanel listenFlaeche_Panel = new JPanel(null, true);
public int x1 = 10;
public int y1 = 165;
public Panel cp ;
// Ende Attribute
public frame(String title) {
// Frame-Initialisierung
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) { dispose(); }
});
int frameWidth = 1274;
int frameHeight = 552;
setSize(frameWidth, frameHeight);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - getSize().width) / 2;
int y = (d.height - getSize().height) / 2;
setLocation(x, y);
setResizable(false);
final Panel cp = new Panel(null);
add(cp);
// Anfang Komponenten
header.setBounds(0, 0, 1275, 73);
header.setText("Listen-Visualisierungs-Tool - LVT");
header.setFont(new Font("Arial", Font.BOLD, 20));
header.setHorizontalAlignment(SwingConstants.CENTER);
header.setHorizontalTextPosition(SwingConstants.CENTER);
cp.add(header);
beenden_Button.setBounds(1096, 454, 137, 49);
beenden_Button.setText("Beenden");
beenden_Button.setMargin(new Insets(2, 2, 2, 2));
beenden_Button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
beenden_Button_ActionPerformed(evt);
}
});
beenden_Button.setCursor(new Cursor(Cursor.HAND_CURSOR));
beenden_Button.setVisible(true);
cp.add(beenden_Button);
jPanel1.setBounds(16, 352, 193, 145);
jPanel1.setOpaque(true);
jPanel1.setBackground(new Color(0xC0C0C0));
jPanel1.setEnabled(true);
cp.add(jPanel1);
aktionen_Label.setBounds(16, 312, 193, 41);
aktionen_Label.setText(" Aktionen");
aktionen_Label.setFont(new Font("Arial", Font.PLAIN, 16));
aktionen_Label.setForeground(new Color(0x333333));
aktionen_Label.setOpaque(true);
aktionen_Label.setBackground(new Color(0xC0C0C0));
aktionen_Label.setVisible(true);
cp.add(aktionen_Label);
aktionen_Combo.setBounds(8, 32, 177, 25);
aktionen_Combo.setModel(new DefaultComboBoxModel(new String[] {"", "Sortieren", "Neuer Knoten", "Knoten löschen"}));
jPanel1.add(aktionen_Combo);
ausfuehren_Button.setBounds(8, 88, 177, 33);
ausfuehren_Button.setText("Ausführen");
ausfuehren_Button.setMargin(new Insets(2, 2, 2, 2));
ausfuehren_Button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
ausfuehren_Button_ActionPerformed(evt);
}
});
ausfuehren_Button.setCursor(new Cursor(Cursor.HAND_CURSOR));
jPanel1.add(ausfuehren_Button);
listenFlaeche_Panel.setBounds(0, 112, 1260, 161);
listenFlaeche_Panel.setOpaque(false);
listenFlaeche_Panel.setBorder(new javax.swing.border.LineBorder(Color.BLACK));
cp.add(listenFlaeche_Panel);
//int x1 = 10;
//int y1 = 165;
int abstand = 79;
//cp . add ( neuerKnoten ( x1, y1 ) ) ;
// Ende Komponenten
setVisible(true);
} // end of public frame
// Anfang Methoden
public void beenden_Button_ActionPerformed(ActionEvent evt) {
dispose ( ) ;
} // end of beenden_Button_ActionPerformed
public void ausfuehren_Button_ActionPerformed(ActionEvent evt) {
int auswahl = aktionen_Combo . getSelectedIndex ( ) ;
switch ( auswahl )
{
case 1 :
//sortieren ( ) ;
break ;
case 2 :
int neu = knotenWert ( ) ;
/*if ( neu != -1 )*/ cp . add ( neuerKnoten ( x1, y1, neu ) ) ;
break ;
case 3 :
break ;
default : break ;
}
} // end of ausfuehren_Button_ActionPerformed
public JPanel neuerKnoten ( int x, int y, int wert )
{
String text = String.valueOf( wert );
JPanel kreisPanel = new JPanel ( null )
{
public void paint( Graphics g )
{
g . setColor( Color . YELLOW ) ;
g . fillOval ( 0, 0, 50, 50 ) ;
}
} ;
kreisPanel . setBounds(x, y, 100, 100);
kreisPanel . setCursor(new Cursor(Cursor.TEXT_CURSOR));
JLabel textLabel = new JLabel (text);
textLabel.setBounds(x-10, y-165, 70, 160);
textLabel.setFont(new Font("Arial", Font.BOLD, 20));
textLabel.setHorizontalAlignment(SwingConstants.CENTER);
textLabel.setHorizontalTextPosition(SwingConstants.CENTER);
textLabel . setVisible (true);
listenFlaeche_Panel . add (textLabel);
return kreisPanel ;
}
public int knotenWert ( )
{
String antwort = JOptionPane.showInputDialog(null,
"Geben Sie den Wert des Knotens ein!",
"Knoten hinten einfügen",
JOptionPane.QUESTION_MESSAGE);
int numbers = -1 ;
try
{
numbers = Integer.parseInt(antwort);
}
catch ( NumberFormatException e )
{
//try
//{
if ( ! antwort . equals ( null ) )
JOptionPane.showMessageDialog(null, "Geben Sie eine Zahl ein!");
//}
//catch ( NullPointerException n ) { System . out . println ( "trololololol" ) ; }
}
catch ( NullPointerException n ) { System . out . println ( "trololololol" ) ; }
return numbers ;
}
// Ende Methoden
public static void main(String[] args) {
new frame("Listenvisualisierung");
} // end of main
} // end of class frame
Fehlermeldung:
Code:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at frame.ausfuehren_Button_ActionPerformed(frame.java:129)
at frame$3.actionPerformed(frame.java:94)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:703)
at java.awt.EventQueue.access$000(EventQueue.java:102)
at java.awt.EventQueue$3.run(EventQueue.java:662)
at java.awt.EventQueue$3.run(EventQueue.java:660)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:676)
at java.awt.EventQueue$4.run(EventQueue.java:674)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:673)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)