Hi, ich hab mir hier mal einen eigenen DateienReader geschrieben, aber wenn ich ihn verwenden will als Color, dann funktioniert der Reader nicht, wieso?
Reader:
TestClass
FehlerException
Was mache ich denn falsch???
Der Datei inhalt erste Zeile hat den Inhalt "red"#
Der Datei inhalt zweiter Zeile hat den Inhalt "green"#
Reader:
Java:
import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.IOException;
public class ColorC
{
Color foreground;
Color background;
public String path = "F:/JExcercises/JPad/Color.sav";
public ColorC() throws FileNotFoundException, IOException
{
String backgroundstring = new Methods().readData(path, 0);
String foregroundstring = new Methods().readData(path, 1);
if(backgroundstring.equals("lightGray"))
{
background = Color.lightGray;
}
else if(backgroundstring.equals("gray"))
{
background = Color.gray;
}
else if(backgroundstring.equals("darkGray"))
{
background = Color.darkGray;
}
else if(backgroundstring.equals("black"))
{
background = Color.black;
}
else if(backgroundstring.equals("red"))
{
background = Color.red;
}
else if(backgroundstring.equals("pink"))
{
background = Color.pink;
}
else if(backgroundstring.equals("orange"))
{
background = Color.orange;
}
else if(backgroundstring.equals("yellow"))
{
background = Color.yellow;
}
else if(backgroundstring.equals("green"))
{
background = Color.green;
}
else if(backgroundstring.equals("magenta"))
{
background = Color.magenta;
}
else if(backgroundstring.equals("cyan"))
{
background = Color.cyan;
}
else if(backgroundstring.equals("blue"))
{
background = Color.blue;
}
//
if(foregroundstring.equals("lightGray"))
{
foreground = Color.lightGray;
}
else if(foregroundstring.equals("gray"))
{
foreground = Color.gray;
}
else if(foregroundstring.equals("darkGray"))
{
foreground = Color.darkGray;
}
else if(foregroundstring.equals("black"))
{
foreground = Color.black;
}
else if(foregroundstring.equals("red"))
{
foreground = Color.red;
}
else if(foregroundstring.equals("pink"))
{
foreground = Color.pink;
}
else if(foregroundstring.equals("orange"))
{
foreground = Color.orange;
}
else if(foregroundstring.equals("yellow"))
{
foreground = Color.yellow;
}
else if(foregroundstring.equals("green"))
{
foreground = Color.green;
}
else if(foregroundstring.equals("magenta"))
{
foreground = Color.magenta;
}
else if(foregroundstring.equals("cyan"))
{
foreground = Color.cyan;
}
else if(foregroundstring.equals("blue"))
{
foreground = Color.blue;
}
}
public Color getForegroundColor()
{
return foreground;
}
public Color getBackgroundColor()
{
return background;
}
}
TestClass
Java:
package JavaPad;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
@SuppressWarnings("serial")
public class JavaPad extends javax.swing.JFrame
{
@SuppressWarnings("static-access")
public JavaPad() throws FileNotFoundException, IOException
{
super("JavaPad");
this.setVisible(true);
Toolkit tk = null;
Dimension d = tk.getDefaultToolkit().getScreenSize();
this.setSize(d);
// ////////////////////////////
JMenuBar bar = new JMenuBar();
this.setJMenuBar(bar);
bar.setBackground(new ColorC().getBackgroundColor());
bar.setForeground(new ColorC().getForegroundColor());
JMenuItem Start = new JMenuItem("OUAIS!");
bar.add(Start);
Start.setForeground(new ColorC().getForegroundColor());
}
public static void main(String[] args) throws FileNotFoundException, IOException
{
new JavaPad();
System.out.println("This Programm is Written by 'Developer_X' 2009.");
System.out.println("For Java-Forum.org");
System.out.println("This Programm is 'the JavaPad'");
}
}
FehlerException
Java:
Exception in thread "main" java.lang.NullPointerException
at JavaPad.ColorC.<init>(ColorC.java:33)
at JavaPad.JavaPad.<init>(JavaPad.java:26)
at JavaPad.JavaPad.main(JavaPad.java:37)
Was mache ich denn falsch???
Der Datei inhalt erste Zeile hat den Inhalt "red"#
Der Datei inhalt zweiter Zeile hat den Inhalt "green"#