System.out.println in gui--- question

Hello People.
First of all, I'm new to the forums, so if it doesn't belong here, plese tell me where to post questions like this.
The Problem:
I have a GUI and another class,which contains the Program.
Here's the code of my class:
int Battle(String CharName) {
          System.out.println(CharName + " Is fighting agains a monster");
          while (CharHP > 0 && MonsterHP != 0) {
               MonsterHP = MonsterHP - CharDmg;
               System.out.println("The monster has " + MonsterHP + "Hitpoints left ");
               CharHP = CharHP - MonsterDamage;
               System.out.println(CharName + " has " + CharHP + " Hitpoints left");
          if (MonsterHP == 0) {
               System.out.println(CharName + "Has lost the fight!");
               CharEXP = CharEXP + 20;
               System.out.println("You have gained " + CharEXP + " Exp");
          if (CharHP == 0) {
               System.out.println("You have lost the fight!");
          return CharHP;
     }So what would be the code to print all the "System.out.println's" here into the gui test area?

camickr wrote:
Check out the [Message Console|http://www.camick.com/java/blog.html?name=message-console].
Just out of curiosity, how do you come up with ideas for all the awesome stuff on your blog?

Similar Messages

  • General question regarding System.out.println

    Just for my knowledge fellas,
    When you have a few System.out.println's in your code, what happens to the lines written to standard out when you run your application from the executable jar file? I know if you run your app in cmd prompt, then the lines are outputted to the cmd screen, and in Netbeans, in the output section...but where do those lines go when you run the app as an executeable? Are they still written, but there's nothing to show the written lines?
    Thanks.
    ...DJVege...

    Just for my knowledge fellas,
    When you have a few System.out.println's in your
    code, what happens to the lines written to standard
    out when you run your application from the executable
    jar file?They get written to standard out, usually the console... doesn't matter at all if it's a JAR or not.
    I know if you run your app in cmd prompt,
    then the lines are outputted to the cmd screen, and
    in Netbeans, in the output section...but where do
    those lines go when you run the app as an
    executeable?cmd screen. Or Java console if you run javaw.

  • How do you change system.out.println colour?

    Hi, I am developing some basic rmi client/server applications, I have an 2D array on a central server being read/written by remote clients. all the development is using system.out. statements at the moment (hopefully being replaced by GUI later) my question is when a client remote calls a read operation, and reads an array location, eg x3, y4 I want to print the location contents in a different colour to indicate the read, at the moment the displayArray() simply has nested for loops to cycle through the array and System.out.println statements to get it to the screen. I wonder is there a simple way to change the colour of system.out type statements? thanks for any help

    I could be wrong, but I don't think that is possible. The System.out and other streams are just streams of characters, and doesn't contain any data about the characters. You could possibly get it to work if you knew which terminal the stream was going to and if the terminal had escape commands that could set colors. BBS browsers have that functionality, but I think that would be a hard path to follow.
    If you are printing out a lot of data and need some color to aid it's readability, try printing directly to your graphic context:
    Graphics g = getGraphics();
    g.setColor(Color.white);
    g.drawString("Hello",100,100);

  • Where to see the System.out.println() messages

    I deploy my application in Oracle9ias . I have some System.out.println() statements in java class files.
    When I run the application I need to know where I can see those println() statements.

    The Member Feedback forum is for suggestions and feedback for OTN Developer Services. This forum is not monitored by Oracle support or product teams and so Oracle product and technology related questions will not be answered. We recommend that you post this thread to the Application Server-General forum. The URL is:
    Oracle Application Server - General

  • System.out.println capture to buffer

    Hi All,
    My application runs other application in back. How can I capture system.out.println() written by another application & display via dialog box.
    Like :execl() or execv() function in C runtime library. Where every printf() message printed to passed buffer.
    Thank you,
    Avin Patel

    If i understand your question correctly, you should execute command for you help.html file. The system will run default browser.
    such as:
    void runBrowser(String file)
    {String cmd = null;   
         Process p;   
              try  {       
                   String os = System.getProperty("os.name");            
                   if (os != null && os.startsWith("Windows")) {           
                        if (os.startsWith("Windows 9") || os.startsWith("Windows Me")) 
                        // Windows 9x/Me               
                             cmd = "start " + file;
    else
                        // Windows NT/2000/XP               
                             cmd = "cmd /c start " + file;
    p = Runtime.getRuntime().exec(cmd);            
    catch(IOException x)
    // couldn't exec browser
    System.err.println("Could not invoke browser, command=" + cmd);
    }

  • System.out.println crashes wireless toolkit

    I'm using system.out.println calls to create debugging commands to test my application. They mostly work but if I try to print out a lot at once the wireless toolkit crashes.
    This is all on my computer, not on any mobile device.
    The error I get is:
    Exception in thread "Child process stdout copier" java.lang.ClassCastException: sun.java2d.NullSurfaceData cannot be cast to sun.java2d.d3d.D3DSurfaceData
         at sun.java2d.d3d.D3DRenderer.copyArea(D3DRenderer.java:55)
         at sun.java2d.d3d.D3DSurfaceData.copyArea(D3DSurfaceData.java:638)
         at sun.java2d.SunGraphics2D.doCopyArea(SunGraphics2D.java:1986)
         at sun.java2d.SunGraphics2D.copyArea(SunGraphics2D.java:1968)
         at javax.swing.BufferStrategyPaintManager.copyArea(BufferStrategyPaintManager.java:315)
         at javax.swing.RepaintManager.copyArea(RepaintManager.java:1228)
         at javax.swing.JViewport.blitDoubleBuffered(JViewport.java:1604)
         at javax.swing.JViewport.windowBlitPaint(JViewport.java:1573)
         at javax.swing.JViewport.setViewPosition(JViewport.java:1118)
         at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.vsbStateChanged(BasicScrollPaneUI.java:1027)
         at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.stateChanged(BasicScrollPaneUI.java:1016)
         at javax.swing.DefaultBoundedRangeModel.fireStateChanged(DefaultBoundedRangeModel.java:348)
         at javax.swing.DefaultBoundedRangeModel.setRangeProperties(DefaultBoundedRangeModel.java:285)
         at javax.swing.DefaultBoundedRangeModel.setValue(DefaultBoundedRangeModel.java:151)
         at javax.swing.JScrollBar.setValue(JScrollBar.java:446)
         at com.sun.kvem.toolbar.MainWindow$ConsoleStream.write(Unknown Source)
         at java.io.PrintStream.write(PrintStream.java:430)
         at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
         at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
         at com.sun.kvem.environment.StreamCopier.run(Unknown Source)
         at java.lang.Thread.run(Thread.java:619)Am I doing something wrong or is this a bug in the toolkit?
    Once I get this exception the whole toolkit becomes unresponsive and I have to close it and re-open.

    mydreamgirl, welcome to the forum. Please don't post in threads that are long dead and don't hijack another poster's thread. When you have a question, start your own topic. Feel free to provide a link to an old post that may be relevant to your problem.
    I'm locking this thread now.
    db

  • Sustitution of System.out.println in Graphical mode

    Dear Sirs:
    I am changing my applications to graphical mode. I would like to know what is the command that substitutes System.out.println in graphical mode. Thanks in advance

    I am not sure exactly what you mean when you say you are changing your apps to graphical mode,
    I assume you will be using Swing?
    If you will be using a gui in the place of a command prompt program, you may need to completely redesign your app (I'm not sure I can help you with that).
    In a Java applet, and application, you can still use System.out.println. It will print to the console while your app runs. I use it pretty often for simple debugging (Although I use JBuilder and the option for the execution Log, if you are in windows and expect the size of the errors to be large an don't have something like this, you may want to run the output into a file using the IO package).
    Hope this helps you,
    Dan Hughes
    Dear Sirs:
    I am changing my applications to graphical mode. I
    would like to know what is the command that
    substitutes System.out.println in graphical mode.
    Thanks in advance

  • System.out.println in J2ME

    Hi...
    My question is very simple. When we write System.out.println("ok") ; it's prints on sun wtk toolkit window but when we run code on actual mobile where it prints.
    Hope you understand.

    hi
    iam using xml parser to display document it displaying on window it should dislpay on emulater screen
    My question is very simple. When we write System.errt.println("ok") ; it's prints on sun wtk toolkit window but when we run code on actual mobile where it prints.
    Hope you understand.

  • System.out.println in EJB

    Hi I have given System.out.println in my EJB object. But I am not able to see the output in my console. But when I give printStackTrace in my JSP(from where I can EJB)....it is displaying the exception....
    So my question is Can we give System.out... in EJB?. Should we set any property to see the output of System.out...in the console?.

    Here is my code
    From UserManager I call the EJB
    public boolean validateSignOn(String strUserName,String strPassword) throws ProdSchedException{
    try{
    UserMgrHome home = (UserMgrHome)getEJBHome("UserMgr",UserMgrHome.class);
    UserMgr userMgr = home.create();
    return userMgr.validateSignOn(strUserName,strPassword);
    catch(RemoteException rex){
    ServerLog.log(rex.getMessage(),ServerLog.ERROR);
    throw new ProdSchedException(rex,"Server Failed");
    catch(CreateException cex){
    ServerLog.log(cex.getMessage(),ServerLog.ERROR);
    throw new ProdSchedException(cex,"Create Exception");
    This is my EJB code
    import javax.ejb.*;
    import java.rmi.RemoteException;
    import java.util.*;
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import org.w3c.dom.*;
    import java.io.*;
    * User Manager Session Bean
    public class UserMgrEJB implements SessionBean {
    SessionContext cntx;
    public boolean validateSignOn(String strUserName,String strPassword) throws ProdSchedException{     
    UserDAO dao = new UserDAO();
         System.out.println("Inside EJB");
    boolean bValidUser = dao.validateUser(strUserName,strPassword);
    if(!bValidUser){
    throw new ProdSchedException("Invalid User");
    return bValidUser;
    //Bean methods
    public void ejbCreate(){
         System.out.println("Inside EJB Create");
    public void ejbRemove(){
    public void ejbActivate(){
         System.out.println("Inside EJB Activate");
    public void ejbPassivate(){
    public void setSessionContext(SessionContext cntx){
    this.cntx = cntx;
    This is mu UserDAO code
    public class UserDAO extends DAO{
    public boolean validateUser(String userName,String password) throws ProdSchedException{
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet result = null;
         System.out.println("Inside validateUser in DAO");
    try{
              boolean bIsValidUser = true;
         String selectStatement = "SELECT SYSDATE from DUAL";
         conn = getConnection();
    stmt = conn.prepareStatement(selectStatement);
    result = stmt.executeQuery();
    while(result.next()){
    bIsValidUser = true;
    return bIsValidUser;
    catch(SQLException sqex){
    ServerLog.log(sqex.getMessage(),ServerLog.ERROR);
    throw new ProdSchedException(sqex,sqex.getMessage());
         finally{
    try{
    close(conn,stmt,result);
    catch(ProdSchedException slex){
                   ServerLog.log(slex.getMessage(),ServerLog.ERROR);
    throw slex;
    } // end class
    And the error I get in the console is this(since I have given printStackTrace in my JSP)
    ProdSchedException: SQL Error
    at UserDAO.validateUser(UserDAO.java:
    44)
    at UserMgrEJB.validateSignOn(
    UserMgrEJB.java:26)
    at UserMgrEJB_p3hctp_EOImpl.v
    alidateSignOn(UserMgrEJB_p3hctp_EOImpl.java:46)
    at UserManager.validateSignOn(User
    Manager.java:20)
    at jsp_servlet._public.__login._jspService(__login.java:123)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
    at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
    (ServletStubImpl.java:1094)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
    pl.java:437)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
    pl.java:319)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
    n.run(WebAppServletContext.java:5626)
    at weblogic.security.service.SecurityServiceManager.runAs(SecurityServic
    eManager.java:685)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
    rvletContext.java:3213)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
    pl.java:2555)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:251)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:219)

  • I have jave 7 I'm trying underscore option in String.   as String strNum = "1000_000";System.out.println("..abc..."  Integer.parseInt(strNum)); but getting error. could you please help in this?

    Hi,
    There is a new feature added in java 7 on integer, called as underscore '_" and it is working fine
    if it is a normal int variable  but if it is coming with String jvm throw the error.
    if  any one of you have java8 installed on your PC can you check this is working on that version.
    int a = 1000_000;   
    String strNum = "1000_000";
    // System.out.println("..abc..."+ Integer.parseInt(strNum));
    System.out.println("a..."+a);
    Thank you,
    Shailesh.

    what is your actual question here?
    bye
    TPD

  • Where does System.out.println go?

    Hi Everyone: I know I've seen this topic before, but I'm still having some trouble. I would like to debug my EJBs, and so I've added some System.out.println statements to them. Where does that go? I've looked at the defaultTrace.trc files in the
    C:\usr\sap\P48\JC00\j2ee\cluster\server0\log
    folder, and haven't found any of the text that I think I am writing. I appreciate any guidance! Ian.

    Hi lan,
    I was facing the same question earlier, and now I think I have figured out one possible answer. Actually, where the System.out.println goes is up to the Server Admin to config. There is a default SYSTEM.OUT log controller ( under location controller side) pre-defined to cater for all System.out.println(). All the System.out.println() output is considered as INFO type log message. However, this default SYSTEM.OUT controller is not assigned with any real log destination, thus, we cannot find the output anywhere.
    If you goes to the log configurator (using Visual Admin), you can locate this SYSTEM.OUT controller , and add in a default (Anonymous) destionation for it . (you need to toggle on the advance edit mode from the top menu , then you can add modify the destination settings of a Controller).
    For Anonymous destionation, the println() output will sure go to the defaultTrace.trc (better view it using Log Viewer, instead of viewing it from the log file ).
    Or , you can define a separate file (e.g. c:\temp\myStd.log ) as the log destination ..
    Last but not the least, you need to set the ForceSingleTraceFile setting from 'YES' to 'NO' , then you can see your "myStd.log".
    To change the ForceSingleTraceFile , go to Visual Admin, J2EE server --> Kernel --> LogManager.
    Hope you find the above useful.

  • Disable or restrict System.out.println() statements on client side

    Hi All,
    This might be a stupid question, but i am still going ahead and asking the question.
    Is there a way to disable or restrict System.out.println() statements in applet code from executing on the client side by using settings in proxy server or firewall or other security settings.
    Thanks
    Nag

    Hi All,
    This might be a stupid question, but i am still going
    ahead and asking the question.
    Is there a way to disable or restrict
    System.out.println() statements in applet code from
    executing on the client side by using settings in
    proxy server or firewall or other security settings.
    System.out.println() calls are executed on the client machine, and thus do not pass through any firewalls or proxies. If the applet is signed, you can redirect the System.out, by System.setOut(...).

  • How can I show a System.out.println(""); into a JSP?

    Is a simple doubt that would help me a lot to reach other thing that I wished reach with a JSP.
    Thank you!!!

    Hi!!!
    Thank you to answer me......my question�is because�my problem is a little more complicated��let me tell you�.
    My problem is that I wish to do some queries to a table of a Municipalities DB, I have read about that....and according with the exemples....my JSP...should be running and executing very well....but I haven�t had success with that...:(
    My JSP file is:
    <!doctype html public "-//w3c//dtd html 3.2//en">
    <html>
    <!-- Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.-->
    <head>
    <title>Query of Municipalities</title>
    </head>
    <body bgcolor=#FFFFFF>
    <font face="Helvetica">
    <h1>
    <font color=#DB1260>
    Municipalities List
    </font>
    </h1>
    <%@ page import="
    weblogic.db.jdbc.*,
    weblogic.html.*,
    java.sql.*
    " %>
    <p>
    <%
    Connection conn = null;
    try {
    Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:weblogic:pool:DESAPool");
    catch (Exception e) {
    e.printStackTrace();
    Statement stmt = conn.createStatement();
    stmt.execute("select * from cat_municipio");
    ResultSet rs = stmt.getResultSet();
    while (rs.next()) {
    System.out.println(rs.getInt("cve_municipio") + " - " + rs.getInt("cve_sepomex") + " - " + rs.getString("desc_municipio"));
    stmt.close();
    conn.close();
    %>
    <p>Please call Mary with any updates ASAP!
    <p>
    <font size=-1>Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    </font>
    </font>
    </body>
    </html>
    My result obtained is the following:
    Municipalities List
    Please call Mary with any updates ASAP!
    Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    I don�t obtain nothing.....is like DB table were without information......but in reality the DB table has information.....and I can obtain it with the following JSP:
    <!doctype html public "-//w3c//dtd html 3.2//en">
    <html>
    <!-- Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.-->
    <head>
    <title>Query of Municipalities</title>
    </head>
    <body bgcolor=#FFFFFF>
    <font face="Helvetica">
    <h1>
    <font color=#DB1260>
    Municipalities List
    </font>
    </h1>
    <%@ page import="
    weblogic.db.jdbc.*,
    weblogic.html.*,
    java.sql.*
    " %>
    <p>
    <%
    Connection conn = null;
    try {
    Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:weblogic:pool:DESAPool");
    // Fetch all records from the database in a TableDataSet
    DataSet dSet = new TableDataSet(conn, "cat_municipio").fetchRecords();
    TableElement tE = new TableElement(dSet);
    tE.setBorder(1);
    out.print(tE);
    } catch (SQLException sqle) {
    out.print("Sorry, the database is not available.");
    out.print("Exception: " + sqle);
    } catch (Exception e) {
    out.print("Exception occured: " + e);
    } finally {
    if(conn != null)
    try {
    conn.close();
    } catch(SQLException sqle) {}
    %>
    <p>Please call Mary with any updates ASAP!
    <p>
    <font size=-1>Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    </font>
    </font>
    </body>
    </html>
    and with this JSP I obtain all the following information:
    Municipalities List
    CVE_MUNICIPIO CVE_SEPOMEX DESC_MUNICIPIO
    1 1 ACAJETE
    2 2 ACATENO
    3 3 ACATLAN
    4 4 ACATZINGO
    5 5 ACTEOPAN
    Now...I need that the first JSP work very well, because...with that way...I can do queries and obtain the needed results for showing them in the Browser......
    So, I already find out�.that�any string that I send to the browser with System.out.println(); isn�t showed�.so it is the reason of my question�..how I can see my results of a query using a loop (like a for, while) resolving it....I think my problem would be resolved.
    So...I hope you understand me, and you could help me please...thanks.....
    Mary
    P.D. I also attempted with the following JSP...but the result is the same....I don�t obtain none result...
    <!doctype html public "-//w3c//dtd html 3.2//en">
    <html>
    <!-- Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.-->
    <head>
    <title>Query of Municipalities</title>
    </head>
    <body bgcolor=#FFFFFF>
    <font face="Helvetica">
    <h1>
    <font color=#DB1260>
    Municipalities List
    </font>
    </h1>
    <%@ page import="
    weblogic.db.jdbc.*,
    weblogic.html.*,
    java.sql.*
    " %>
    <p>
    <%
    Connection conn = null;
    try {
    Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:weblogic:pool:DESAPool");
    catch (Exception e) {
    e.printStackTrace();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("select CVE_MUNICIPIO, CVE_SEPOMEX, DESC_MUNICIPIO from cat_municipio");
    while (rs.next()) {
    System.out.println(rs.getInt(1) + " - " + rs.getInt(2) + " - " + rs.getString(3));
    rs.close();
    stmt.close();
    conn.close();
    %>
    <p>Please call Mary with any updates ASAP!
    <p>
    <font size=-1>Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    </font>
    </font>
    </body>
    </html>

  • Synchronized use of System.out.println()

    So I am again at the point of part of my program running ahead of itself out of the call stack and ruining the sequence or order of printing.
    I read that System.out.println() is synchronized so how may it be used to wait() until notified to continue and not ruin the output?

    jverd wrote:
    Always Learning wrote:
    YES SIR EJP! SIR! I thank you for the assistance because using only System.out and synchronizing worked beautifully.You said you're not using multiple threads. If this is true, then there's no reason to synchronize anything. The output will appear on System.out in exactly the order you send it there.
    Nos if only I could figure out dependencies to make it work with out and err.You have to stop and think about it for a minute. You know that when you call println() on either one of those two streams, the output may be buffered an not necessarily go immediately to the console. From that you can reason that if you call out.println() first, and then err.println(), that you could end up with err's buffer getting flushed first, and the output appearing on the console in a different order than that in which your code executed the calls.
    You are of course not surprised by this, given that you know that out and err are completely independent and just happen to end up at the same destination in this particular case.
    So, as a first guess, you might reasonably think that, since buffering is obviously the culprit here, calling flush() on each stream after each print() or println() call should eliminate the problem. In a multithreaded environment, this wouldn't be sufficient, of course, but it's a logical approach to try here.
    Another tidbit to make note of is that the System class has setOut() and setErr() calls. Since you're looking at out and err in the same console, you presumably don't care about the distinction between them (which makes me wonder why you're using them both in the first place, instead of just using one). If you're just going to mush them together into the same console anyway, then you can use setOut() or setErr() to make them the same stream, and things will be ordered as you expect.Very interesting Jverd and I think there may yet be life in what I would like to do. I did not know or was not immediately aware of these things. I will give it a try.
    To answer your question, I am using them both because, like logging, they are distinct in the Eclipse console (black for out and red for err). With your patch I just tried that distinction has faded but the output is sequenced the same so I do appreciate you noting this. Learn something new in Java each time I am doing a project. I considered using logging and putting errors in a window but I am not sure if I should do that; just not enough experience with it.
    Edited by: Always Learning on Oct 23, 2011 9:28 AM

  • Is it possible to overide System.out.println()....

    Hi all,
    I have a program which uses System.out.println() a lot. As the whole program needed to be in GUI form, I have to abbandon the console window and print all my outputs to a special text pane which I have already created and tested.
    My problem is, is there a way for me to keep my System.out.println() statements as they are and print the outputs to my text pane instead of printing it to the console?
    Can I use some kind of overriding of System.out.println()? If so can anybody tell me how to do it?
    Thank you all in advance

    Hi again guys,
    I managed to get the system.out working. Thanks again. But I was trying to do the same to system.in using a class that inherits from InputStream and failed, can you help me out again pliz.
    following is a simplified version of the code. problem I have is that the input I get on readButton click(see the code) is always -1. The code doesn't wait for user input . How can I correct this. please help Thanx
    public class Main() implements ActionListener
        JTextPane textPane;
        JButton readButton;
        public Main()
                this.initGUI();
                Console myConsole = new Console(this.textPane);
                System.setIn(new myInputStream(myConsole));
        private void initGUI()
               this.textPane = new JTextPane();
               this.readButton = new readButton();
               this.readButton.AddActionListener(this);
                //code to create the GUI and show the textPane
               //follows
         public void ActionPerformed(ActionEvent e)
                 try
                             int keyCode = System.in.read();
                     }Catch(Exception e)
                 System.out.println("Pressed Key Code is " + keyCode);          
         public static void main(String[] args)
                   new Main();
    public class Console extends KeyListener
         JTextPane textPane;
         int pressedKey = -1;
         public console(JTextPane textPane)
                 this.textPane = textPane;
                 this.textPane.addKeyListener(this);
        public void keypressed(KeyEvent e)
                this.pressedKey = e.getKeyCode();
       public int read()
               return this.pressedKey;
    public class myInputStream extends InputStream
                Console console;
                public myInputStream(Console console)
                       this.console = console;
                public int read()
                       return this.console.read();
    }

Maybe you are looking for