Von einer untergeordneten Klasse auf die Variablen der Main zugreifen

Der Vollständigkeit halber alle drei Klassen

1.code
2.GUI
3.Handler

(ich entschuldige mich jetzt schonmal fürs naming, habs noch nicht überarbeitet...

Java:
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import java.sql.*;
import GUI.Frame;


public class code
{
    public static char[] matrix = new char[20];
    public static int date = 0;
    public static char show[] = new char[10];
    public static boolean wrong = false;
    public static String[][] rowData = new String[50][3]; 
	public static String[] columnNames = {" ", " ", " "};
	public static code main; 
	public static void main ( String[] args ) 	
	{		
		 final GUI.Frame Frame = new GUI.Frame();
		 
	    		  // src.Frame.run.inst.update();
		 
	     String driver = "org.hsqldb.jdbcDriver";
	     String URL = "jdbc:hsqldb:hsql://localhost/xdb";
	     String tbstring = new String("CUSTOMER");
	     String heads[] = new String[50];
	     heads[0] = "ID";
	     heads[1] = "FIRSTNAME";
	     heads[2] = "LASTNAME";
	     
	  
	     
	     TableModel jTable1Model = new DefaultTableModel( rowData, columnNames);
	     GUI.Frame.table.setModel(jTable1Model);
	     
	     loaddriver(driver);
	     Connection con = connect(URL); 				  //liefert Connection aus URL 
	     Spaltenbeschriftung(con,GUI.Frame.table, tbstring, heads); //Liefert Spaltenbeschriftung für Tabel der Tabelle tbstring der Spalten heads
		 showdb(tbstring, GUI.Frame.table, con); 					  //zeige tabelle tbstring in table
		 disconnect(con);								  //beendet Verbindung con
		  
		 Frame.runme(main);
		 
		 //UPDATE customer Set FIRSTNAME = 'Laura2' WHERE FIRSTNAME = 'Laura'
	     
		 while(true){}	     

}		
	
	
	public char[] getShow()
	{
	return show;
	}
	

	public void setWrong(boolean b)
	{
		wrong = b;
	}
	public boolean getWrong()
	{
		return wrong;
	}
	
	public void setMatrix(char[] chars)
	{
	matrix = chars;
	}
	public char[] getMatrix()
	{
	return matrix;
	}
	
	public static void showdb(String tbstring, JTable table, Connection con) //liefert gesamten inhalt der Tabelle tbstring für tabelle table
	{
		try
	     {
	    	 String query = "SELECT * FROM ";
			 Statement stmt = con.createStatement();
	    	 ResultSet rs = stmt.executeQuery( query.concat(tbstring));
	    	 int count = 0;
	    	 while ( rs.next() )  
	    	 {
	    		 Frame.table.setValueAt(rs.getString(1),count,0);	  
	    		 table.setValueAt(rs.getString(2),count,1);	    
	    		 table.setValueAt(rs.getString(3),count,2);
	    		 count++;
	    	 }
	     }
		 catch(SQLException e)    
		 {      e.printStackTrace();    }    
		 finally    
		 {      
			 if ( con != null )        
			 try { con.close(); } 
		 	 catch ( SQLException e ) { e.printStackTrace(); }    
		 }
	}
	public static void Spaltenbeschriftung(Connection con, JTable table, String tbstring, String heads[]) //Liefert Spaltenbeschriftung für Tabel der Tabelle tbstring der Spalten heads
	  {   
	    try
	    {
		
		DatabaseMetaData dbMetaData = con.getMetaData();
        ResultSet columnsRS = dbMetaData.getColumns(con.getCatalog(), "%", tbstring, "%");
	      int i = 0;
	      while(columnsRS.next())
	      {
	    	  if(i!=(table.getColumnCount()+1))  
	    	  {
	    		 if(columnsRS.getString("COLUMN_NAME").equals(heads[i]))
	    		  Frame.table.getColumnModel().getColumn(i++).setHeaderValue(columnsRS.getString("COLUMN_NAME"));
	          }
	      }
	      columnsRS.close();
	    }      
	      catch(SQLException e)
			{
				e.printStackTrace();
			}
	  }
	public static Connection connect(String URL) //verbindet mit Datenbank
	{
		Connection con = null;
		try
		{
		 con = DriverManager.getConnection(URL,"sa","");	
		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
	return con;
	}	
	public static void disconnect(Connection con) //beendet Verbindung
	{
		{
		 if(con != null)
			 try{con.close();} catch( SQLException e) {e.printStackTrace();}
		}
	}
	public static void loaddriver(String driver) // Läd Treiber
	{
		try{  Class.forName( driver );}
	     catch ( ClassNotFoundException e ){  // Blöd: Treiber konnte nicht geladen werden.  
	    	 System.err.println( "Keine Treiber-Klasse!");
	     }	
	}
	public static void wandle(int day, int year) //wandelt aus day year in day month year DD MM YYYY 
	 {
	     int month = 1;
	     boolean schaltjahr = false;
		 boolean hit = false;
	     int store = year;
		 //filtere Datum aus Datamatrix Code -> Schreibe in date / year
	     //Schaltjahres filter (-4 => 0 Schaltjahr)

	     while(year>0)
         year = year - 4;	
	     if(year==0)
	     schaltjahr = true;
	          
	     year = store; //year zurücksetzen 
	     
	     if(day > 31)  //januar
	     {
	    	 day = day - 31;
	    	 month++;
	     }
	     else
	    	 hit = true;
	     
	     if(day > 28 && schaltjahr == false && hit == false)
	     {
	    	 day = day - 28;
	    	 month++;
	     }
	     else
	     {
         if(schaltjahr == false)
         hit = true;
         
	     if(day > 29 && schaltjahr == true && hit == false)
	      {
	    	 day = day - 29;
	    	 month++;                  //februar
	      }
	      else 
	      {
	      hit = true;
	      }	     
	     }
	     
	     if(day > 31 && hit == false)  //märz
	     { 
	    	 day = day - 31;
	    	 month++;
	     }
	     else 
	    	 hit = true;
	     
	     if(day > 30 && hit == false)   //april
	     {	 
	    	 day = day - 30;
	    	 month++;
	     }
	     else
	    	 hit = true;
	
	     if(day > 31 && hit == false) // mai
	     {	 
	    	 day = day - 31;
	    	 month++;
	     }	 
	     else
	    	 hit = true;
	     
	     if(day > 30 && hit == false) // juni
	     {	 
	    	 day = day - 30;
	    	 month++;
	     }
	     else
	    	 hit = true;
	     
	     if(day > 31 && hit == false) // juli
	     {	 
	    	 day = day - 31; 
	    	 month++;
	     }
	     else
	    	 hit = true;
	     if(day > 31 && hit == false)
	     {	 
	    	 day = day - 31; //august
	    	 month++;
	     }
	     else
	    	 hit = true;
	     
	     if(day > 30 && hit == false)
	     {	 
	    	 day = day - 30; //september
	    	 month++;
	     }
	     else
	    	 hit = true;
	     
	     if(day > 31 && hit == false)
	     {	 
	    	 day = day - 31; //oktober
	    	 month++;
	     }
	     else
	    	 hit = true;
	     
	     if(day > 30 && hit == false)
	     {	 
	    	 day = day - 30; //november
	    	 month++;
	     }
	     else
	    	 hit = true;
	     
	     if(day <= 31 && hit == false)
	    	 hit = true;
	     

	     if(day > 31 || month > 12 || year > 9999 || hit == false)
	     { 
	    	 wrongformat();
	     }
	     else
	     format(day, month, year);
	 };	 
	public static void format(int day, int month, int year ) // Wandelt aus day month year in DD.MM.YYYY in show[]
	 {
	 
	int store;
	
	store = day;
	day = (day % 10);
	store = (store - day)/10 ;	
	store = store +48;
	day = day + 48;
	
	
	show[0]= (char)store;
	show[1]= (char)day;	
	show[2]= '.';	
	
	store = month;
	month = (month % 10);
	store = (store - month)/10 ;	
	store = store +48;
	month = month + 48;
	
	show[3]= (char)store;
	show[4]= (char)month;
	show[5]= '.';
	
	store = year;
	year = (year % 10);
	store = (store - year)/10 ;	
	store = store +48;
	year = year + 48;
	
	
	show[6] = '2';
	show[7] = '0';
	show[8] = (char)store;
	show[9] = (char)year;
			
	 }
	public static void wrongformat() //ausgabe bei falscheingabe!
	{
		Frame.result.setText("WRONG FORMAT");
		wrong = true;
	}	 
}
Java:
package GUI;
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

import javax.swing.WindowConstants;

import handling.Handler;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Frame extends javax.swing.JFrame {
	private static final long serialVersionUID = 1L;
	public JTabbedPane sides;
	public JPanel tools;
	public static JButton dateconvknopf;
	public static JTextField result;
	private JScrollBar scroll;
	public JPanel DB;
	public static JButton dmconvknopf;
	public static JTextField dmconvtf;
	private JLabel dmconvlabel;
	public static JTextField dateconvtf;
	private JLabel dateconvlabel;
	public JPanel jPanel3;
	public JPanel panel1;
	public static JTable table = new JTable();
	public static Object main; 
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
	
			public void run() {
				Frame inst = new Frame();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	

	     
	
	public Frame(){
		super();
		initGUI();
	}
	
	public void runme(Object me)
	{
		main = me;
		Frame inst = new Frame();
		inst.setLocationRelativeTo(null);
		inst.setVisible(true);
	}
	
	
	
	
	public void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{
				sides = new JTabbedPane();
				getContentPane().add(sides, BorderLayout.CENTER);
				{
					tools = new JPanel();
					GridLayout toolsLayout = new GridLayout(1, 1);
					toolsLayout.setHgap(5);
					toolsLayout.setVgap(5);
					toolsLayout.setColumns(1);
					tools.setLayout(toolsLayout);
					sides.addTab("Tools", null, tools, null);
					{
						panel1 = new JPanel();
						GridBagLayout panel1Layout = new GridBagLayout();
						panel1Layout.rowWeights = new double[] {0.0, 0.0, 0.0, 0.1};
						panel1Layout.rowHeights = new int[] {40, 40, 40, 7};
						panel1Layout.columnWeights = new double[] {0.0, 0.0, 0.1};
						panel1Layout.columnWidths = new int[] {185, 240, 7};
						panel1.setLayout(panel1Layout);
						/*GridLayout panel1Layout = new GridLayout(3, 1);
						panel1Layout.setHgap(5);
						panel1Layout.setVgap(5);
						panel1Layout.setColumns(1);
						panel1.setLayout(panel1Layout);*/
						tools.add(panel1);
						{
							dateconvlabel = new JLabel();
							panel1.add(dateconvlabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
							dateconvlabel.setText("DDDYY");
						}
						{
							result = new JTextField("",21);
							panel1.add(result, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
						}
						{
							dmconvknopf = new JButton();
							panel1.add(dmconvknopf, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
							dmconvknopf.setText("CONVERT DMX ");
							dmconvknopf.addActionListener(new Handler(1, main));
						}
						{
							dateconvknopf = new JButton();
							panel1.add(dateconvknopf, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
							dateconvknopf.setText("CONVERT DATE");
							dateconvknopf.addActionListener(new Handler(2, main));

						}
						{
							dateconvtf = new JTextField(" ", 21);
							panel1.add(dateconvtf, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
						}
						{
							dmconvtf = new JTextField("",21);
							panel1.add(dmconvtf, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
						}
						{
							dmconvlabel = new JLabel();
							panel1.add(dmconvlabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
							dmconvlabel.setText("CONVERT DMX (Injektor)");
						}
						
					}
				}
				{
					DB = new JPanel();
					sides.addTab("DB", null, DB, null);
					{					
						scroll = new JScrollBar();
						table.add(scroll);
						DB.add(table);

					}

				}
			}
			pack();
			this.setSize(800, 400);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}


Java:
package handling;

import java.awt.event.*;



public class Handler implements ActionListener 
{

	//private static final long serialVersionUID = 1L;
		public int id;
		public static Handler main;
		public Handler(int i, Object me) 
		{
		id = i;
		main = me;
		}

		public void actionPerformed(ActionEvent ev)
		{		
			switch(id)
			{
				case 1:
				{
					main.setWrong(false);
					main.setMatrix((GUI.Frame.dmconvtf.getText()).toCharArray());
					main.wandle(1,2);//(matrix[6]-48)*100+(matrix[7]-48)*10+(matrix[8]-48), (matrix[10]-48)*10+(matrix[11]-48));
					if(wrong!=true)
					{
						String str = new String(show);	 
						GUI.Frame.result.setText(str);
					}
		
				}	
				case 2:
				{
					wrong = false;
					matrix = (GUI.Frame.dateconvtf.getText()).toCharArray();
					wandle((matrix[0]-48)*100+(matrix[1]-48)*10+(matrix[2]-48), (matrix[3]-48)*10+(matrix[4]-48));
	    		
	    		
	    		
					if(wrong!=true)
					{
						String str = new String(show);	 
						GUI.Frame.result.setText(str);
					}
			
				
				
				}	
			} 
		}



}
 
Also bevor wir hier weiter machen, solltest du dir vielleicht noch ein paar Artikel zum Thema OOP, Codedesign, Pattern, etc. durchlesen. Dein Code hält sich an keinerlei Standards (auch nicht ansatzweiße).

Damit dein Problem jetzt aber gelöst ist, ersetzt du bitte diese Zeile im Handler:
Java:
public static Handler main;
...durch...
Java:
public static code main;
 
Ich weiß mein Gekrickel ist noch sehr wild....
setzte ich die Zeile entsprechend bekomme ich:

code cannot be resolved to a type

liegt das an meiner Ordner struktur?

handler und GUI liegen jeweils in einem eigenen Ordner enstsprechend dem Packagenamen...
 
Du wirst wahrscheinlich noch das Package von der Klasse "code" in deine Klasse "Handler" importen müssen.

Mit was für einer Entwicklungsumgebung arbeitest du denn? (Eclipse, NetBeans, etc.)
 
Arbeite mit eclipse

mal ne blöde Frage macht das von der Strucktur her Sinn das Package von code in den Handler zu importieren?


Aber wenns Funktioniert mir recht, nur wie?


Um mal zu den Konventionen zurückzukommen... was brennt denn am meisten im auge?

Jetzt schonmal tausend Dank für deine gestohlene Zeit!


Ach ja ich hab den quellcode der Klasse Handler natürlich noch nicht komplett angepasst alles was in Case 2 passiert ist noch unbearbeitet...
 
Zuletzt bearbeitet:
So, ich hab deinen Code jetzt mal ein "wenig" überarbeitet. Jetzt ist es wenigstens nicht mehr ganz so graußig. Und die Überischt hat dadurch auch einige Pluspunkte bekommen. Schau dir den Code jetzt einfach mal an, wenn du fragen dazu haben solltest, nur zu.

Klasse DBWindow & MyActionListener:
Java:
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;


/**
 * Bei dir heißt diese Klasse "GUI"
 */
public class DBWindow extends JFrame
{
	private static final String TB_STRING = "CUSTOMER";
	private static final String URL = "jdbc:hsqldb:hsql://localhost/xdb";

	private final TableModel model;
	private final JTable table;

	private final JTextField result;
	private final JTextField dmconvtf;
	
	private boolean isWrongFormat;

	public DBWindow() {
		super("Demo");

		this.model = new DefaultTableModel(new String[] {" ", " ", " "}, 50);
		this.table = new JTable();
		table.setModel(model);

		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		{
			JTabbedPane sides = new JTabbedPane();
			getContentPane().add(sides, BorderLayout.CENTER);
			{
				JPanel tools = new JPanel();
				GridLayout toolsLayout = new GridLayout(1, 1);
				toolsLayout.setHgap(5);
				toolsLayout.setVgap(5);
				toolsLayout.setColumns(1);
				tools.setLayout(toolsLayout);
				sides.addTab("Tools", null, tools, null);
				{
					JPanel panel1 = new JPanel();
					GridBagLayout panel1Layout = new GridBagLayout();
					panel1Layout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.1 };
					panel1Layout.rowHeights = new int[] { 40, 40, 40, 7 };
					panel1Layout.columnWeights = new double[] { 0.0, 0.0, 0.1 };
					panel1Layout.columnWidths = new int[] { 185, 240, 7 };
					panel1.setLayout(panel1Layout);
					/*
					 * GridLayout panel1Layout = new GridLayout(3, 1);
					 * panel1Layout.setHgap(5);
					 * panel1Layout.setVgap(5);
					 * panel1Layout.setColumns(1);
					 * panel1.setLayout(panel1Layout);
					 */
					tools.add(panel1);
					{
						JLabel dateconvlabel = new JLabel();
						panel1.add(dateconvlabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
								new Insets(0, 0, 0, 0), 0, 0));
						dateconvlabel.setText("DDDYY");
					}
					{
						result = new JTextField("", 21);
						panel1.add(result, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
								new Insets(0, 0, 0, 0), 0, 0));
					}
					{
						JButton dmconvknopf = new JButton();
						panel1.add(dmconvknopf, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
								new Insets(0, 0, 0, 0), 0, 0));
						dmconvknopf.setText("CONVERT DMX ");
						dmconvknopf.addActionListener(new MyActionListener(1));
					}
					{
						JButton dateconvknopf = new JButton();
						panel1.add(dateconvknopf, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
								new Insets(0, 0, 0, 0), 0, 0));
						dateconvknopf.setText("CONVERT DATE");
						dateconvknopf.addActionListener(new MyActionListener(2));
					}
					{
						JTextField dateconvtf = new JTextField(" ", 21);
						panel1.add(dateconvtf, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
								new Insets(0, 0, 0, 0), 0, 0));
					}
					{
						dmconvtf = new JTextField("", 21);
						panel1.add(dmconvtf, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
								new Insets(0, 0, 0, 0), 0, 0));
					}
					{
						JLabel dmconvlabel = new JLabel();
						panel1.add(dmconvlabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
								new Insets(0, 0, 0, 0), 0, 0));
						dmconvlabel.setText("CONVERT DMX (Injektor)");
					}
				}
			}
			{
				JPanel DB = new JPanel();
				sides.addTab("DB", null, DB, null);
				{
					JScrollBar scroll = new JScrollBar();
					table.add(scroll);
					DB.add(table);
				}
			}
		}
		this.setSize(800, 400);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		DBWindow window = new DBWindow();

		DBConnection dbCon = null;
		try {
			dbCon = new DBConnection(DBConnection.DRIVER_HSQLDB);

			String heads[] = new String[50];
			heads[0] = "ID";
			heads[1] = "FIRSTNAME";
			heads[2] = "LASTNAME";
			
			// Verbindung zur DB aufbauen und Daten holen
			dbCon.connect(URL);
			
			String[] columnHeader = dbCon.getColumnHeader(TB_STRING, heads);
			window.setTableColumnHeader(columnHeader);
			
			String[][] values = dbCon.getValues(TB_STRING);
			window.setTableValues(values);
		} catch(ClassNotFoundException e) {
			System.err.println("Treiber konnte nicht geladen werden");
			e.printStackTrace();
		finally {
			dbCon.disconnect();
		}
		
		window.open();
	}

	/**
	 * @param columnHeader
	 */
	public void setTableColumnHeader(String[] columnHeader) {
		for(int i = 0; i < columnHeader.length; i++) {
			table.getColumnModel().getColumn(i).setHeaderValue(columnHeader);
		}
	}

	/**
	 * @param values
	 */
	public void setTableValues(String[][] values) {
		for(int i = 0; i < values.length; i++) {
			table.setValueAt(values[0], i, 0);
			table.setValueAt(values[1], i, 1);
			table.setValueAt(values[2], i, 2);
		}
	}

	/**
	 * 
	 */
	public void open() {
		setVisible(true);
	}

	/**
	 * wandelt aus day year in day month year DD MM YYYY
	 * 
	 * @param cs 
	 * @param day
	 * @param year
	 */
	public char[] wandle(int day, int year) {
		char show[] = new char[10];
		isWrongFormat = false;

		int month = 1;
		boolean schaltjahr = false;
		boolean hit = false;
		int store = year;
		// filtere Datum aus Datamatrix Code -> Schreibe in date / year
		// Schaltjahres filter (-4 => 0 Schaltjahr)
		while(year > 0)
			year = year - 4;
		if(year == 0)
			schaltjahr = true;
		year = store; // year zurücksetzen
		if(day > 31) // januar
		{
			day = day - 31;
			month++;
		} else
			hit = true;
		if(day > 28 && schaltjahr == false && hit == false) {
			day = day - 28;
			month++;
		} else {
			if(schaltjahr == false)
				hit = true;
			if(day > 29 && schaltjahr == true && hit == false) {
				day = day - 29;
				month++; // februar
			} else {
				hit = true;
			}
		}
		if(day > 31 && hit == false) // märz
		{
			day = day - 31;
			month++;
		} else
			hit = true;
		if(day > 30 && hit == false) // april
		{
			day = day - 30;
			month++;
		} else
			hit = true;
		if(day > 31 && hit == false) // mai
		{
			day = day - 31;
			month++;
		} else
			hit = true;
		if(day > 30 && hit == false) // juni
		{
			day = day - 30;
			month++;
		} else
			hit = true;
		if(day > 31 && hit == false) // juli
		{
			day = day - 31;
			month++;
		} else
			hit = true;
		if(day > 31 && hit == false) {
			day = day - 31; // august
			month++;
		} else
			hit = true;
		if(day > 30 && hit == false) {
			day = day - 30; // september
			month++;
		} else
			hit = true;
		if(day > 31 && hit == false) {
			day = day - 31; // oktober
			month++;
		} else
			hit = true;
		if(day > 30 && hit == false) {
			day = day - 30; // november
			month++;
		} else
			hit = true;
		if(day <= 31 && hit == false)
			hit = true;
		if(day > 31 || month > 12 || year > 9999 || hit == false) {
			result.setText("WRONG FORMAT");
			isWrongFormat = true;
			return null;
		} else
			show = format(day, month, year);
		
		return show;
	};

	/**
	 * Wandelt aus day month year in DD.MM.YYYY in show[]
	 * 
	 * @param day
	 * @param month
	 * @param year
	 */
	public char[] format(int day, int month, int year) {
		char show[] = new char[10];

		int store;
		store = day;
		day = (day % 10);
		store = (store - day) / 10;
		store = store + 48;
		day = day + 48;
		show[0] = (char) store;
		show[1] = (char) day;
		show[2] = '.';
		store = month;
		month = (month % 10);
		store = (store - month) / 10;
		store = store + 48;
		month = month + 48;
		show[3] = (char) store;
		show[4] = (char) month;
		show[5] = '.';
		store = year;
		year = (year % 10);
		store = (store - year) / 10;
		store = store + 48;
		year = year + 48;
		show[6] = '2';
		show[7] = '0';
		show[8] = (char) store;
		show[9] = (char) year;

		return show;
	}

	/**
	 * Bei dir heißt diese Klasse "Handler"
	 */
	private final class MyActionListener implements ActionListener
	{
		private final int id;

		/**
		 * @param id
		 */
		public MyActionListener(int id) {
			this.id = id;
		}

		/* (non-Javadoc)
		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
		 */
		public void actionPerformed(ActionEvent e) {
			switch (id) {
				case 1: {
					String text = dmconvtf.getText();
					char[] charArray = text.toCharArray();
					
					char[] c = wandle((charArray[6]-48)*100+(charArray[7]-48)*10+(charArray[8]-48), 
							(charArray[10]-48)*10+(charArray[11]-48));
					if(!isWrongFormat) {
						String str = new String(c);
						result.setText(str);
					}
				}
				case 2: {
					String text = dmconvtf.getText();
					char[] charArray = text.toCharArray();
					
					char[] c = wandle((charArray[0] - 48) * 100 + (charArray[1] - 48) * 10 + (charArray[2] - 48), 
							(charArray[3] - 48) * 10 + (charArray[4] - 48));
					if(!isWrongFormat) {
						String str = new String(c);
						result.setText(str);
					}
				}
			}
		}
	}
}

Klasse DBConnection:
Java:
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;

/**
 * Bei dir heißt diese Klasse "Code"
 */
public class DBConnection
{
	public static final String DRIVER_HSQLDB = "org.hsqldb.jdbcDriver";

	private Connection con = null;

	/**
	 * @param driver
	 */
	public DBConnection(String driver) throws ClassNotFoundException {
		Class.forName(driver);
	}

	/**
	 * verbindet mit Datenbank
	 * 
	 * @param driver
	 * @param URL
	 * @return
	 */
	public Connection connect(String URL) {
		try {
			con = DriverManager.getConnection(URL, "sa", "");
		} catch(SQLException e) {
			e.printStackTrace();
		}
		return con;
	}

	/**
	 * beendet Verbindung
	 */
	public void disconnect() {
		if(con != null) {
			try {
				con.close();
				con = null;
			} catch(SQLException e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * Liefert Spaltenbeschriftung für Tabel der Tabelle tbstring der Spalten heads
	 * 
	 * @param dbCon
	 * @param table
	 * @param tbstring
	 * @param heads
	 * @return 
	 */
	public String[] getColumnHeader(String tbstring, String heads[]) {
		if(con == null) {
			System.err.println("Connection is null");
			return null;
		}

		String[] columnHeader = new String[heads.length];
		ResultSet columnsRS = null;
		try {
			DatabaseMetaData dbMetaData = con.getMetaData();
			columnsRS = dbMetaData.getColumns(con.getCatalog(), "%", tbstring, "%");
			int i = 0;

			while(columnsRS.next()) {
				if(columnsRS.getString("COLUMN_NAME").equals(heads[i])) {
					columnHeader[i] = heads[i];
					i++;
				}
			}
		} catch(SQLException e) {
			e.printStackTrace();
		}
		return columnHeader;
	}

	/**
	 * liefert gesamten Inhalt der Tabelle tbstring für tabelle table
	 * 
	 * @param tbstring
	 * @param table
	 * @param con
	 */
	public String[][] getValues(String tbstring) {
		if(con == null) {
			System.err.println("Connection is null");
			return null;
		}

		List<String[]> values = new LinkedList<String[]>();
		try {
			String query = "SELECT * FROM ";
			Statement stmt = con.createStatement();
			ResultSet rs = stmt.executeQuery(query.concat(tbstring));
			//int count = 0;
			while(rs.next()) {
				values.add(new String[] {
						rs.getString(1),
						rs.getString(2),
						rs.getString(3)
				});
			}
		} catch(SQLException e) {
			e.printStackTrace();
		}

		String[][] result = new String[values.size()][3];
		return values.toArray(result);
	}
}

Ich sage nicht das der Code (so wie er jetzt ist) perfekt ist, aber er ist auf jedenfall besser als vorher. ;)
 
Zuletzt bearbeitet:
Ähm ... ich hätte da mal noch ne Frage über die zusätzliche Referenz auf THIS :
Warum machst du dir die Mühe und deklarierst ne zweite Referenz die auf das selbe Objekt zeigt ? Es reicht völlig aus wenn du der Methode die eine Referenz auf deine Klasse erwartet einfach THIS übergibst :
Java:
SubClass object=new SubClass(this);

Auch finde ich deine STATIC-Konstrukte erlich gesagt : schrecklich.
Du solltest dir wirklich mal OOP angucken und von diesem Anfänger-Mist alles in MAIN und STATIC zu machen weggehen.
 
Zurück