顯示字的java代碼,java輸出文字代碼

求Java窗體代碼,可顯示文本.

importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.KeyEvent;importjava.awt.event.KeyListener;importjavax.swing.JButton;importjavax.swing.JEditorPane;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JPanel;importjavax.swing.JTextField;publicclassWindowTestextendsJFrameimplementsActionListener,KeyListener{privatestaticfinallongserialVersionUID=1L;/***主方法*/publicstaticvoidmain(String[]args){WindowTestwin=newWindowTest();}/***下面是具體實現(xiàn)*/JTextFieldtext;JButtonbutton;JEditorPanetextArea;publicWindowTest(){super("測試窗體");text=newJTextField(15);text.addKeyListener(this);JPanelp1=newJPanel();p1.add(newJLabel("輸入字符:"));p1.add(text);button=newJButton("清除");button.addActionListener(this);p1.add(button);p1.setBounds(5,5,220,100);textArea=newJEditorPane();textArea.setBounds(1,1,216,200);JPanelp2=newJPanel();p2.add(newJLabel("顯示字符:"));p2.add(textArea);p2.setBounds(5,115,340,220);JPanelp3=newJPanel();p3.add(p1);p3.add(p2);add(p3);setBounds(160,60,400,300);setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}@OverridepublicvoidkeyPressed(KeyEvente){}@OverridepublicvoidkeyReleased(KeyEvente){if(e.getKeyCode()==KeyEvent.VK_ENTER){textArea.setText("");}else{Stringstr=text.getText();textArea.setText(str);}}@OverridepublicvoidkeyTyped(KeyEvente){}@OverridepublicvoidactionPerformed(ActionEvente){text.setText("");textArea.setText("");}}

網(wǎng)站建設哪家好,找創(chuàng)新互聯(lián)建站!專注于網(wǎng)頁設計、網(wǎng)站建設、微信開發(fā)、小程序定制開發(fā)、集團企業(yè)網(wǎng)站建設等服務項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了陽朔免費建站歡迎大家使用!

Java如何顯示字符

java顯示字符,直接輸出即可,如果遇到需要轉義的字符,需要再加一個/,如下代碼:

public?class?ceshi?{

public?static?void?main(String[]?args)?{

char?ch?=?'a';

System.out.println(ch);

char?ch1?=?'\\';//?這個需要轉義

System.out.println(ch1);

char?ch2?=?'{';

System.out.println(ch2);

}

}

運行結果如下:

如何在Java的Label中顯示多行文字

1、在Label上不能使用\n換行,必須使用Html標簽

2、可以在java代碼里面使用JLabel實現(xiàn),如下:

JLabel lblLabel = new JLabel("title"); //title是指標簽的名稱

lblLabel.setText("htmlbody換行br /換行/body/html");

本文標題:顯示字的java代碼,java輸出文字代碼
鏈接地址:http://muchs.cn/article40/hssoho.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供標簽優(yōu)化服務器托管、網(wǎng)站設計虛擬主機、商城網(wǎng)站品牌網(wǎng)站建設

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名