Hi im trying to build a console ( like windows cmd ).I guess i did the gui stuff correct but i cant carry users input to console.I mean if user types hello and enter console should display it.There are 2 classes one is the main other is console.
import javax.swing.*;
import javax.swing.text.StyledDocument;
public class ana extends JFrame {
public JFrame frame;
public JTextPane console;
public JTextField input;
public JScrollPane scrollpane;
public boolean trace= false;
public StyledDocument document;
public static void main(String[] args) {
konsol k = new konsol();
k.konsolum();
}
}
This is the console class:
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.UIManager;
import javax.swing.text.BadLocationException;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
public class konsol {
public JFrame frame;
public JTextPane console;
public JTextField input;
public JScrollPane scrollpane;
public boolean trace= false;
public StyledDocument document;
public void konsolum() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception e) {}
frame = new JFrame();
frame.setTitle("Konsol");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
console = new JTextPane();
input = new JTextField();
scrollpane = new JScrollPane();
frame.add(input,BorderLayout.SOUTH);
frame.add(scrollpane,BorderLayout.CENTER );
frame.setSize(660,350);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setVisible(true);
frame.getContentPane().setBackground(new Color(50,50,50));
console.setEditable(false);
console.setFont(new Font("Courier New",Font.PLAIN,12));
console.setOpaque(false);
document = console.getStyledDocument();
scrollpane.getViewport().setOpaque(false);
scrollpane.setOpaque(false);
scrollpane.setBorder(null);
input.setEditable(true);
input.setCaretColor(Color.WHITE);
input.setForeground(Color.WHITE);
input.setOpaque(false);
input.setFont(new Font("Courier New",Font.PLAIN,12));
input.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String text=input.getText();
}
});
input.addKeyListener(new KeyListener(){
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
});
}
}
I dont really know what to write inside `actionPerformed`. My main aim is to build a console which will understand commands and do stuff with them. Thanks
What I have tried:
addding console.setText(text);
to actionperformed but not workin