提前:我是初学者,我的代码可能包含多个失败,这是我第二次使用JFrame应用程序进行编码,而且在运行之前我没有遇到任何明显的错误,这就是为什么我在这里努力寻找答案。我相信所有这些或至少大多数人都提到了同样的问题。我想我错过了一些必要的东西(所有这些未知来源)。
我的代码:
Sub ZoneImp()
Dim FirstCol As Integer, LastCol As Integer, FirstLin As Integer, FirstLin As Integer
FirstCol = 1
LastCol = 3
FirstLin = 1
LastLin = 6
'Here I create my Area for printing
Sheets("MyTargetSheet").PageSetup.PrintArea = Range(Cells(FirstLin, FirstCol), Cells(LastLin, LastCol)).Address
End Sub
我没有真正得到导致错误的原因,所以我在这里发布了我的整个代码,如果这太过分了,请对不起。
这是我得到的错误:
package BWINF;
import java.io.*;
import java.util.Scanner;
import java.awt.*;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Aufgabe_3 extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField eingabe;
private JTextField ausgabe;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Aufgabe_3 frame = new Aufgabe_3();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Aufgabe_3() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 431, 359);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setBounds(10, 11, 240, 240);
contentPane.add(panel);
eingabe = new JTextField();
eingabe.setFont(new Font("Arial", Font.BOLD, 15));
eingabe.setBounds(260, 73, 145, 20);
contentPane.add(eingabe);
eingabe.setColumns(10);
JLabel lblBitteGebenSie = new JLabel("Bitte geben sie ein,");
lblBitteGebenSie.setFont(new Font("Arial", Font.PLAIN, 12));
lblBitteGebenSie.setBounds(260, 11, 145, 20);
contentPane.add(lblBitteGebenSie);
JLabel lblWelcheDateiAusgelesen = new JLabel("welche Datei ausgelesen");
lblWelcheDateiAusgelesen.setFont(new Font("Arial", Font.PLAIN, 12));
lblWelcheDateiAusgelesen.setBounds(260, 27, 153, 20);
contentPane.add(lblWelcheDateiAusgelesen);
JLabel lblWerdenSoll = new JLabel("werden soll:");
lblWerdenSoll.setFont(new Font("Arial", Font.PLAIN, 12));
lblWerdenSoll.setBounds(260, 42, 108, 20);
contentPane.add(lblWerdenSoll);
JLabel lblDatei1 = new JLabel("");
lblDatei1.setEnabled(true);
lblDatei1.setVisible(false);
lblDatei1.setFont(new Font("Arial", Font.PLAIN, 12));
lblDatei1.setBounds(132, 273, 266, 35);
contentPane.add(lblDatei1);
JLabel lblDatei2 = new JLabel("Datei konnte eingelesen werden!");
lblDatei2.setEnabled(true);
lblDatei2.setVisible(false);
lblDatei2.setFont(new Font("Arial", Font.PLAIN, 12));
lblDatei2.setBounds(132, 283, 229, 14);
contentPane.add(lblDatei2);
JLabel lblAnzahlDerDreiecke = new JLabel("Anzahl der Dreiecke:");
lblAnzahlDerDreiecke.setFont(new Font("Arial", Font.PLAIN, 12));
lblAnzahlDerDreiecke.setBounds(260, 126, 126, 14);
contentPane.add(lblAnzahlDerDreiecke);
ausgabe = new JTextField();
ausgabe.setEditable(false);
ausgabe.setFont(new Font("Arial", Font.PLAIN, 12));
ausgabe.setBounds(260, 153, 86, 20);
contentPane.add(ausgabe);
ausgabe.setColumns(10);
JButton bBerechnen = new JButton("BERECHNEN");
bBerechnen.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
Scanner sc1;
try {
Graphics g = panel.getGraphics();
// User file lesen
String textnumber = eingabe.getText();
java.io.File textfile = new java.io.File(textnumber + ".txt");
if (textfile.exists() && textfile.canRead()) {
lblDatei2.setVisible(true);
} else {
lblDatei1.setVisible(true);
System.exit(0);
}
sc1 = new java.util.Scanner(textfile, "UTF-8");
double readin[] = new double[100]; // NOCH FALSCH
int count = 0;
while (sc1.hasNextLine()) {
String text = sc1.nextLine();
Scanner sc2 = new Scanner(text);
text.replaceAll(".", ",");
System.out.println(text);
while (sc2.hasNextLine()) {
for (int i = 0; i < readin.length; i++) {
readin[i] = sc2.nextDouble();
count++;
System.out.println(readin[i]);
}
}
sc2.close();
}
double endpoints[] = new double[count];
for (int i = 1; i < count; i++) {
readin[i] = endpoints[i];
System.out.println(endpoints[i]);
}
// DRAW LINE OPERATOR jeweils 4 stellen pro linie
for (int i = 0; i < (endpoints.length / 4); i = i + 4) {
g.drawLine((int) endpoints[i], (int) endpoints[i + 1], (int) endpoints[i + 2],
(int) endpoints[i + 3]);
}
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
bBerechnen.setFont(new Font("Arial", Font.PLAIN, 12));
bBerechnen.setBounds(270, 93, 128, 23);
contentPane.add(bBerechnen);
}
}
我认为错误可能出现在第二个扫描仪(sc2)处。