Swing Coding richtig einfügen

skrobi

Mitglied
Als Java Einsteiger habe ich mein erstes Versuchsprogramm geschrieben. Wie unten dargestellt, habe ich es um „ANZAHL TAGE ERMITTELN“ erweitert. Nun läuft es nicht mehr, sondern wird mit folgendem Fehlerhinweis abgebrochen:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: Illegal modifier for the local class Verspgm_02; only abstract or final is permitted at hausdienst_l.Hausdienst_l.main(Hausdienst_l.java:176)

package hausdienst_l;

import …………………………….
import java.time.temporal.Temporal;
import java.time.temporal.ChronoUnit;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Hausdienst_l {
private static final String JComponent = null;
public static void main(String[] args) {

Teil -1- davor eigentliches Programm

/* „ANZAHL TAGE ERMITTELN“

public class Verspgm_02{
public static void main(String[] args) throws Exception {
LocalDate dBefore = LocalDate.parse("2021-12-01", //yyyy-MM-dd von
DateTimeFormatter.ISO_LOCAL_DATE);
LocalDate dAfter = LocalDate.parse("2022-01-14", //yyyy-MM-dd bis
DateTimeFormatter.ISO_LOCAL_DATE);

long diff = dBefore.until(dAfter,ChronoUnit.DAYS);
System.out.println("difference is : "+diff +" days");

}
}

Teil -2- danach eigentliches Programm

Vielleicht kann mir jemand verraten wie ich „ANZAHL TAGE ERMITTELN“ ändern muss, damit mein Programm wieder läuft.

Vorab vielen Dank

skrobi
 
So wie das hier aussieht, versuchst Du innerhalb der main-Methode eine Klasse zu definieren. Evtl. könntest Du mal den kompletten Code einfügen (aber bitte in Code-Tags: in der Toolbar des Foren-Editors links auf </> klicken und dort einfügen).
 
package verspgm_02;

import javax.swing.JFrame; /*public class JTableExamples */
import javax.swing.JScrollPane;
import javax.swing.JTable;

import javax.swing.JFrame; //Import-Anweisung für unseren JFrame
import javax.swing.JLabel; //Import-Anweisung für unser JLabel

import java.util.*; /*Datum Gültigkeitsprüfung*/
import java.util.regex.*;
import java.text.*;

import java.time.LocalDateTime; /*Datum und Zeit ermitteln*/
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.time.LocalDate;

import java.util.GregorianCalendar; /*Tagesdifferenz ermitteln*/

import java.io.*; /*System.out.println*/

import java.util.*;
import java.text.SimpleDateFormat;
import java.text.ParseException;

import java.time.temporal.Temporal;
import java.time.temporal.ChronoUnit;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Verspgm_02 {

private static final String JComponent = null;

public static void main(String[] args) {

String[][] array01 = {
//-----------------:------------:--------------:--------------:-------------:
{ "-frei- ", "Kehrwoche", "Graue Tonne", "Grüne Tonne", "Bio Tonne" },
{ "MP1 ", " ", "ja ", "ja ", "ja " },
{ "MP2 ", " ", "ja ", "ja ", "ja " },
{ "MP3 ", "ja ", "ja ", "ja ", "ja " },
{ "MP4 ", " ", "ja ", "ja ", "ja " },
};

String[][] array02 = {
//{ "Bezeichnung" : Kehrwoche : Graue Tonne : Grüne Tonne : Bio Tonne :
//----------------:--------------:--------------:--------------:-------------:-
{ "Start_TMJ ", "26.11.2021 ", "10.11.2021 ", "27.10.2021 ", "21.10.2021" },
{ "Start_JMT ", " ", " ", " ", " " },
{ "Anz. Tage ", " ", " ", " ", " " },
{ "Wochentag ", "Freitag ", "Mittwoch ", "Mittwoch ", "Donnerstag" },
{ "Rhytmus ", "4-wöchig ", "2-wöchig ", "2-wöchig ", "2-wöchig " },
{ "Mietpartei ", "MP1 ", "MP2 ", "MP3 ", "MP4 " },
//------------------:------------:--------------:--------------:-------------
{ "letztes Mal ", " ", " ", " ", " " },
{ "Mietpartei ", " ", " ", " ", " " },
//-----------------:-------------:--------------:--------------:-------------
{ "nächstes Mal ", " ", " ", " ", " " },
{ "Mietpartei ", " ", " ", " ", " " },
//---------------- -:------------:--------------:--------------:-------------
{ "Kommentar ", " ", " ", " ", " " }
};


Date d = new Date();
Calendar c = Calendar.getInstance();
c.setTime(d);
c.roll(Calendar.HOUR, -0); // -0 = deutsche, -1 = englische Zeit
d = c.getTime();

String date = new SimpleDateFormat("dd-MM-yyyy-HH-mm").format(d); //dd-MM-yyyy-HH-mm
System.out.print("hausdienst_l - Programmstart: ");
System.out.println(date);

System.out.println();
String ttmmjhjj1 = "xxxxxxxxxx" + array02[0][1];

System.out.println();
System.out.println("ttmmjhjj1 = array02[0][1]: " + ttmmjhjj1);

String ttmmjhjj2 = array02[0][2];
System.out.println("ttmmjhjj2 = array02[0][2]: " + ttmmjhjj2);

String ttmmjhjj3 = array02[0][3];
System.out.println("ttmmjhjj3 = array02[0][3]: " + ttmmjhjj3);

String ttmmjhjj4 = array02[0][4];
System.out.println("ttmmjhjj4 = array02[0][4]: " + ttmmjhjj4);

String absolutesStartdatum = ttmmjhjj1;
System.out.println(" ");
System.out.println("absolutes Startdatum: " + absolutesStartdatum);



//*****************************************************************
// Nachfolgender Code bringt den Fehler ????????????????????????
//*****************************************************************

/*
public class Verspgm_02{
public static void main(String[] args) throws Exception {
LocalDate dBefore = LocalDate.parse("2022-01-01", //yyyy-MM-dd von
DateTimeFormatter.ISO_LOCAL_DATE);
LocalDate dAfter = LocalDate.parse("2022-01-15", //yyyy-MM-dd bis
DateTimeFormatter.ISO_LOCAL_DATE);

long diff = dBefore.until(dAfter,ChronoUnit.DAYS);
System.out.println("difference is : "+diff +" days");
}
}
*/

//*****************************************************************
// Vorstehender Code bringt den Fehler ??????????????????????????
//*****************************************************************



System.out.println("Array01 / MIETER UND AKTIVITÄTEN (V O R H E R)");

for (int i = 0; i < array01.length; i++) // i = vertikal
{
for (int j = 0; j < array01.length; j++) // j = horizontal
System.out.print( array01[j].toString() + ", " );
System.out.println();
}


/************************************************************************************/
/* ARRAY02 - A K T I V I T A E T E N T A B E L L E P R O T O K O L L I E R E N */
/************************************************************************************/

System.out.println();
System.out.println("Array02 / AKTIVITAETENTABELLE (V O R H E R)");

for (int i = 0; i < array02.length; i++) // i = vertikal
{
for (int j = 0; j < array02.length; j++) // j = horizontal
System.out.print( array02[j].toString() + ", " );
System.out.println();
}


System.out.println();
System.out.println("Array01 / AKTIVITAETENTABELLE: (N A C H H E R)");
//System.out.println("absolutes Startdatum: " + absolutesStartdatum);

for (int i = 0; i < array01.length; i++) // i = vertikal
{
for (int j = 0; j < array01.length; j++) // j = horizontal
System.out.print( array01[j].toString() + ", " );



System.out.println();
}


/************************************************************************************/
/* ARRAY02 - */
/************************************************************************************/


System.out.println();
Date zeitstempel = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.yyyy");
System.out.println("voher Datum: " + simpleDateFormat.format(zeitstempel));

Date zeitstempel2 = new Date();
SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy.MM.dd");
System.out.println("danach Datum: " + simpleDateFormat.format(zeitstempel2));




// Table
JTable j;

// frame
JFrame t;
//l.setFont(new lFont("Arial", Font.ITALIC 25)); //09.01.2022/ Schriftgrösse ändern
//indem du explizit für jedes JLabel oder so das hier sagst
//setFont(new Font(Schrifttyp, Font.BOLD, Schriftgr));
//wobei Schrifttyp eine Stringvariable mit Inhalt "Courier New" bei mir ist und Schriftgr 12 !

// Label
JLabel l;

// Constructor
Hausdienst_l();
{
// Frame initialization W I N D O W S F E N S T E R
t = new JFrame();

// Frame Title
t.setTitle("(Hausdienst_l) - AKTIVITÄTEN-ÜBERSICHT - TT.MM.JHJJ / HH:MM");


// Data to be displayed in the JTable
String[][] data = {
//{ "Bezeichnung", : Kehrwoche : Graue Tonne : Grüne Tonne : Bio Tonne
// sp1 : sp2 : sp3 : sp4 : sp5
// ------------------:------------:-------------:-------------:----------
// System.out.print( array01[0][0].toString() + ", " );
// System.out.print( array02[0][0].toString() + ", " ); (
{ "Start_TMJ", "z1-sp2", "z1-sp2", "z1-sp2", "z1-sp2" }, //z1
{ "Wochentag", "z1-sp3", "z2-sp3", "z2-sp3", "z2-sp3" }, //z2
{ "Rhytmus", "z1-sp5", "z4-sp5", "z4-sp5", "z4-sp5" }, //z4
{ "Mietpartei", "z1-sp4", "z3-sp4", "z3-sp4", "z3-sp4" }, //z3
// ------------------:------------:-------------:-------------:----------
{ " ", " ", " ", " ", " " }, //z
{ "letztes Mal", "z1-sp5", "z4-sp5", "z4-sp5", "z4-sp5" }, //z
{ "Mietpartei", "z1-sp4", "z3-sp4", "z3-sp4", "z3-sp4" }, //z3
// ------------------:------------:-------------:-------------:----------
{ " ", " ", " ", " ", " " }, //z
{ "nächstes Mal", "z1-sp5", "z4-sp5", "z4-sp5", "z4-sp5" }, //z
{ "Mietpartei", "z1-sp4", "z3-sp4", "z3-sp4", "z3-sp4" }, //z3
// ------------------:------------:-------------:-------------:----------
{ " ", " ", " ", " ", " " }, //z
{ "Kommentar", "z5-feld2", "z5-feld3", "z5-feld4", "z5-feld5" } //z5
};


// Column Names
String[] columnNames = {
//"Bezeichnung", "Kehrwoche", "Graue Tonne", "Grüne Tonne", "Bio Tonne" };
"(TT.MM.JHJJ)", "Kehrwoche", "Graue Tonne", "Grüne Tonne", "Bio Tonne" };

// Initializing the JTable
j = new JTable(data, columnNames);
j.setBounds(30, 40, 200, 300);



// adding it to JScrollPane
JScrollPane sp = new JScrollPane(j);
t.add(sp);

// Frame Size
//t.setSize(500, 200);
t.setSize(600, 400); //RM/09.01.2022/ Pixel: Breite * Höhe

// Frame Visible = true array01
t.setVisible(true);

for(int ix01 = 0; ix01 < array01.length; ix01++){
//System.out.println(array01[ix01]);
}

//l.setFont(new lFont("Arial", Font.ITALIC 25)); //09.01.2022/ Schriftgrösse ändern
t.add(new JLabel("Beispiel JLabel")); //RM/09.01.2022/ Pixel: Breite * Höhe
t.setVisible(true);
// Wir lassen unseren Frame anzeigen
}
}



//***********************************************
//ENDE - public static void main(String[] args) {
//***********************************************

private static void jhjjmmtt(String string) {
// TODO Auto-generated method stub
}

private static void Hausdienst_l() {
// TODO Auto-generated method stub
}

// Driver method
public static void main1(String[] args) {
new Verspgm_02();
}


//**********************************
} //ENDE - public class Hausdienst_l {
//**********************************
 

Neue Themen


Zurück
Oben