Hallo liebe Forenuser,
ich habe schon wieder ein ärgerliches Problem:
Habe ein Programm geschrieben, dass Text-Dateien einlesen kann und diese anhand eines übergebenen Keys verschlüsselt.
Wenn ich das Programm aus Netbeans heraus ausführe (RUN) funktioniert alles
Wenn ich´s über die Konsole aufrufe (java -jar "Pfad\letscryptit.jar") funktioniert es ebenfalls.
Wenn ich aber die JAR-Datei öffnen möchte, meldet er mir, dass die main-class nicht gefunden wurde.
In den Project-Properties steht die richtige Klasse.
Hier mal mein Code
Klasse cryptframe (Main-Class)
Klasse Reader
Klasse Writer
Danke für eure Hilfe!
ich habe schon wieder ein ärgerliches Problem:
Habe ein Programm geschrieben, dass Text-Dateien einlesen kann und diese anhand eines übergebenen Keys verschlüsselt.
Wenn ich das Programm aus Netbeans heraus ausführe (RUN) funktioniert alles
Wenn ich´s über die Konsole aufrufe (java -jar "Pfad\letscryptit.jar") funktioniert es ebenfalls.
Wenn ich aber die JAR-Datei öffnen möchte, meldet er mir, dass die main-class nicht gefunden wurde.
In den Project-Properties steht die richtige Klasse.
Hier mal mein Code
Klasse cryptframe (Main-Class)
Java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cryptpackage;
/**
*
* @author dha
*/
public class cryptframe extends javax.swing.JFrame {
static int key;
static String datname;
/**
* Creates new form cryptframe
*/
public cryptframe() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
abbrechen = new javax.swing.JButton();
decrypt = new javax.swing.JButton();
encrypt = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(255, 153, 0));
jLabel1.setFont(new java.awt.Font("Tahoma", 2, 24)); // NOI18N
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("Let´s Crypt!");
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel4.setText("(leer = test.txt)");
jLabel3.setText("Datei-Name:");
jLabel2.setText("Key eingeben:");
abbrechen.setText("ABBRECHEN");
abbrechen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
abbrechenActionPerformed(evt);
}
});
decrypt.setText("Decrypt");
decrypt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
decryptActionPerformed(evt);
}
});
encrypt.setText("Encrypt");
encrypt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
encryptActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(215, 215, 215)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(97, 97, 97)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(abbrechen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(decrypt, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(encrypt, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(70, 70, 70)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTextField1)
.addComponent(jTextField2)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(206, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(22, 22, 22)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(encrypt))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(decrypt))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(abbrechen))
.addContainerGap(118, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void abbrechenActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jTextField1.setText(null);
jTextField2.setText(null);
jTextField1.setEditable(true);
}
private void decryptActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Writer.letsroll();
String keys = jTextField1.getText();
key = Integer.parseInt(keys);
datname = jTextField2.getText();
}
private void encryptActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String keys = jTextField1.getText();
key = Integer.parseInt(keys);
datname = jTextField2.getText();
if (datname.length() == 0) {
datname = "test.txt";
}
jTextField1.setEditable(false);
Reader.runit();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/*
* Set the Nimbus look and feel
*/
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* [url=http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html]How to Set the Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)[/url]
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(cryptframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(cryptframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(cryptframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(cryptframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new cryptframe().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton abbrechen;
private javax.swing.JButton decrypt;
private javax.swing.JButton encrypt;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration
}
Klasse Reader
Java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cryptpackage;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.LinkedList;
import java.util.List;
public class Reader {
//LinkedList für eingelesene Daten
private List<String> _input = new LinkedList<String>();
public Reader(int key, String datei) {
read(datei);
printInfo();
fileTransfer(key);
printInfo();
write();
}
//Ausgabe der Informationen aus der LinkedList
private void printInfo() {
for (int i = 0; i < _input.size(); i++) {
System.out.println(_input.get(i));
}
}
//Methode um jedes Element der LinkedList zu encodieren
//Parameter ist eine Zahl, welche Anzahl Verschiebungen anzeigt
public void fileTransfer(int key) {
int index = 0;
for (index = 0; index < _input.size(); index++) {
_input.set(index, encode(key, _input.get(index)));
}
}
//Code wird encodiert durch Eingabe des Keys
//Verschiebung findet nur bei Buchstaben statt, alle anderen Zeichen bleiben unberücksichtigt
private String encode(int key, String code) {
int i = 0;
int temp;
char file[] = code.toCharArray();
while (i < code.length()) {
if (file[i] >= 'a' && file[i] <= 'z') {
if ((file[i] + key) > 'z') {
temp = ((file[i] + key) - 'z');
file[i] = (char) (('a' - 1) + temp);
} else {
file[i] = (char) (file[i] + key);
}
} else if (file[i] >= 'A' && file[i] <= 'Z') {
if ((file[i] + key) > 'Z') {
temp = ((file[i] + key) - 'Z');
file[i] = (char) (('A' - 1) + temp);
} else {
file[i] = (char) (file[i] + key);
}
}
i++;
}
return String.valueOf(file);
}
//Datei wird mithilfe des BufferReaders ausgelesen und in die LinkedList geschrieben
private void read(String datei) {
BufferedReader in = null;
String value = "";
try {
in = new BufferedReader(new InputStreamReader(new FileInputStream(
datei)));
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
}
try {
while (null != (value = in.readLine())) {
_input.add(value);
}
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
//LinkedList wird in ein File geschriebne und im Explorer abgespeichert
private void write() {
String text;
BufferedWriter out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("decode.txt")));
for (int i = 0; i < _input.size(); i++) {
text = _input.get(i).toString();
out.write(text, 0, text.length());
out.newLine();
}
} catch (IOException ex) {
System.out.println(ex);
} finally {
if (out != null)
try {
out.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
public static void runit ()
{
new Reader(cryptframe.key, cryptframe.datname);
}
}
Klasse Writer
Java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cryptpackage;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.LinkedList;
import java.util.List;
public class Writer {
//LinkedList für eingelesene Daten
private List<String> _input = new LinkedList<String>();
public Writer(int key, String datei) {
read(datei);
fileTransfer(key);
printInfo();
write();
}
//Ausgabe der Informationen aus der LinkedList
private void printInfo() {
for (int i = 0; i < _input.size(); i++) {
System.out.println(_input.get(i));
}
}
//Methode um jedes Element der LinkedList zu decodieren
//Parameter ist eine Zahl, welche Anzahl Verschiebungen anzeigt
public void fileTransfer(int key) {
int index = 0;
for (index = 0; index < _input.size(); index++) {
_input.set(index, decode(key, _input.get(index)));
}
}
//Code wird decodiert durch Eingabe des Keys
//Verschiebung findet nur bei Buchstaben statt, alle anderen Zeichen bleiben unberücksichtigt
private String decode(int key, String code) {
char[] file = code.toCharArray();
int i = 0;
int temp;
while (i < file.length) {
if (file[i] >= 'a' && file[i] <= 'z') {
if ((file[i] - key) < 'a') {
temp = 'a' - (file[i] - key);
file[i] = (char) (('z' + 1) - temp);
} else {
file[i] = (char) (file[i] - key);
}
} else if (file[i] >= 'A' && file[i] <= 'Z') {
if ((file[i] - key) < 'A') {
temp = 'A' - (file[i] - key);
file[i] = (char) (('Z' + 1) - temp);
} else {
file[i] = (char) (file[i] - key);
}
}
i++;
}
return String.valueOf(file);
}
//Datei wird mithilfe des BufferReaders ausgelesen und in die LinkedList geschrieben
private void read(String datei) {
BufferedReader in = null;
String value = "";
try {
in = new BufferedReader(new InputStreamReader(new FileInputStream(
datei)));
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
}
try {
while (null != (value = in.readLine())) {
_input.add(value);
}
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
//LinkedList wird in ein File geschriebne und im Explorer abgespeichert
private void write() {
String text;
BufferedWriter out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("encode.txt")));
for (int i = 0; i < _input.size(); i++) {
text = _input.get(i).toString();
out.write(text, 0, text.length());
out.newLine();
}
} catch (IOException ex) {
System.out.println(ex);
} finally {
if (out != null)
try {
out.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
public static void letsroll ()
{
new Writer(cryptframe.key, "decode.txt");
}
}
Danke für eure Hilfe!