Hej alle. Har lavet mit hidtil største system, but no work, prøvede at køre min klasse fileReader i et lukket test projekt i Eclipse, der fungerede det, men når jeg kobler det på resten af systemet, med JFrame, JLabels, keylistener osv så virker det ikke.
Når jeg skriver en kommando i min lille "kommandoprompt" og prøver at eksekvere kommandoen, så får jeg intet output..
Please help!
Window.java
- import java.awt.Color;
- import javax.swing.*;
-
- public class Window extends JFrame
- {
- Keyboard keys;
-
- JPanel panel;
- JLabel output, input;
- String command = "";
- String outputString = "";
-
- public Window()
- {
- this.setVisible(true);
- this.setDefaultCloseOperation(EXIT_ON_CLOSE);
- this.setSize(600, 400);
-
- keys = new Keyboard(this);
- this.setFocusable(true);
- this.addKeyListener(keys);
-
- panel = new JPanel();
- this.add(panel);
- panel.setLayout(null);
- panel.setOpaque(true);
- panel.setBackground(Color.BLACK);
-
- output = new JLabel();
- output.setForeground(Color.WHITE);
- output.setBounds(0, 0, 600, 300);
- output.setText("Welcome to DotMS!");
- panel.add(output);
-
- input = new JLabel();
- input.setForeground(Color.WHITE);
- input.setBounds(0, 200, 600, 50);
- input.setText(command);
- panel.add(input);
- }
-
- public void refreshOutput()
- {
- output.setText(outputString);
- }
-
- public void refreshInput()
- {
- input.setText(command);
- }
-
- public static void main(String args[])
- {
- Window main = new Window();
- }
- }
Keyboard.java
- import java.awt.event.KeyListener;
- import java.awt.event.KeyEvent;
-
- public class Keyboard implements KeyListener
- {
- Window Main;
-
- public Keyboard(Window main)
- {
- this.Main = main;
- }
-
- public void keyPressed(KeyEvent e)
- {
- int keyTyped = e.getKeyCode();
-
- if(keyTyped == KeyEvent.VK_1)
- {
- Main.command += "1";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_2)
- {
- Main.command += "2";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_3)
- {
- Main.command += "3";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_4)
- {
- Main.command += "4";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_5)
- {
- Main.command += "5";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_6)
- {
- Main.command += "6";
- Main.refreshInput();
- }
- else if(keyTyped == KeyEvent.VK_7)
- {
- Main.command += "7";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_8)
- {
- Main.command += "8";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_9)
- {
- Main.command += "9";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_0)
- {
- Main.command += "0";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_COMMA)
- {
- Main.command += ",";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_PERIOD)
- {
- Main.command += ".";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_A)
- {
- Main.command += "A";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_B)
- {
- Main.command += "B";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_C)
- {
- Main.command += "C";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_D)
- {
- Main.command += "D";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_E)
- {
- Main.command += "E";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_F)
- {
- Main.command += "F";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_G)
- {
- Main.command += "G";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_H)
- {
- Main.command += "H";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_I)
- {
- Main.command += "I";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_J)
- {
- Main.command += "J";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_K)
- {
- Main.command += "K";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_L)
- {
- Main.command += "L";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_M)
- {
- Main.command += "M";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_N)
- {
- Main.command += "N";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_O)
- {
- Main.command += "O";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_P)
- {
- Main.command += "P";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_Q)
- {
- Main.command += "Q";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_R)
- {
- Main.command += "R";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_S)
- {
- Main.command += "S";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_T)
- {
- Main.command += "T";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_U)
- {
- Main.command += "U";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_V)
- {
- Main.command += "V";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_W)
- {
- Main.command += "W";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_X)
- {
- Main.command += "X";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_Y)
- {
- Main.command += "Y";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_Z)
- {
- Main.command += "Z";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_SPACE)
- {
- Main.command += " ";
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_BACK_SPACE)
- {
- int delete = Main.command.length() - 1;
- Main.command = Main.command.substring(0, delete);
-
- Main.refreshInput();
- }
-
- else if(keyTyped == KeyEvent.VK_ENTER)
- {
- FileReader fr = new FileReader();
-
- Main.outputString = fr.getValue(Main.command);
- Main.refreshOutput();
- Main.command = "";
- Main.refreshInput();
- }
-
- }
-
- public void keyReleased(KeyEvent e)
- {
-
- }
-
- public void keyTyped(KeyEvent e)
- {
-
- }
-
- }
FileReader.java
- import java.awt.Color;
- import java.awt.geom.Rectangle2D;
- import java.io.*;
- import java.lang.*;
- import java.util.*;
-
- public class FileReader
- {
- private static Scanner file;
- private static HashMap<String, String> config = new HashMap<String, String>(); // Key/Value
-
- public static void openFile(String fileName)
- {
- try
- {
- file = new Scanner(new File(fileName));
- }
- catch(Exception e)
- {
- System.out.println("ERROR");
- }
- }
-
- public static void putInHashMap(Scanner f)
- {
- while(f.hasNext())
- {
- String temp, key, value;
- temp = f.nextLine();
- temp.trim();
-
- int a = temp.indexOf(':');
- String[] keyAndValue = temp.split(":");
- key = keyAndValue[0].toLowerCase();
- value = keyAndValue[1].toLowerCase();
-
- config.put(keyAndValue[0], keyAndValue[1]);
- }
- }
-
- public String getValue(String key)
- {
- openFile("res/tihifnis.lolkage");
- putInHashMap(file);
-
- return config.get(key);
- }
- }
FileWriter.java
- import java.io.*;
- import java.lang.*;
- import java.util.*;
-
- public class FileWriter
- {
- Formatter file;
-
- public void openFile(String fileName)
- {
- try
- {
- file = new Formatter(fileName);
- System.out.println("Succesfully found file: " + fileName);
- }
- catch(Exception e)
- {
- System.out.println("Failed finding file: " + fileName);
- }
- }
-
- public void addLine(String line)
- {
-
- }
-
- public void closeFile()
- {
- file.close();
- }
- }
tihifnis.lolkage
tihi:fnis
Indlæg senest redigeret d. 13.12.2012 11:37 af Bruger #16945