我已經使用 Swing 組件撰寫了一個命令終端。下面的代碼片段包含我認為可能是問題的一部分的所有內容。發生的事情是在代碼片段 #1 中,當我呼叫 printBoard() 時,它會忽略 values[][] 陣列中的空格。我嘗試切換到 String[][] 而不是 char[][] 但它沒有用。
如果您需要更多資訊,請詢問。謝謝你的幫助!
編輯:
您需要使用
使用布局管理器...

免費恢復能力。您也不必擔心 DPI 或可訪問性之類的事情可能會做什么。
null or "pixel perfect" layouts are an illusion. To many factor go into determining how a component should be sized and how components should be laid out in relationship to each other.
A lot of work has gone into solving these issues, Swing makes use of layout managers, other frameworks do similar things.
Rather then spending a lot of time tearing your hair out over why the layout breaks on some others computer, just make use of the layout managers that are already available to you - for example, BorderLayout would be a fantastic for your current layout
what's wrong with KeyListener?
KeyListener is too low level a API for your needs. Since all you're doing is monitoring for the Enter key anyway, you might as well make use of the ActionListener support. You're also assuming the key code is constant.
如果要過濾輸入,則應使用DocumentFilter.
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/388298.html
