當前位置:首頁 » 編程語言 » java輸入文本框

java輸入文本框

發布時間: 2023-09-21 03:22:48

java怎麼添加文本框

  • 如果是頁面的話:<input type="text" name="namevalue" id="namevalue"/>;這樣就定義了一個input的文本框,注意下,id具有唯一性,不要重復了。

  • 如果是GUI的話:TextFiledjt=new TextFiled("");這樣就定義了一個輸入域(文本框),之後通過其他panel(根據實際需要添加)的add(jt)方法進行添加文本框,即可實現。

② JAVA輸入和輸出文本框怎麼寫,求解答!

importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.awt.event.WindowAdapter;
importjava.awt.event.WindowEvent;

importjavax.swing.JButton;
importjavax.swing.JFrame;
importjavax.swing.JTextField;


{
privateJTextFieldname=newJTextField("someone");

privateJTextFieldtext=newJTextField();

privateJButtonbutton=newJButton("輸入");

publicXXFrame()
{
super("一個測試框框");

name.setBounds(40,40,200,20);
button.setBounds(260,40,100,20);
text.setBounds(40,110,200,20);

this.setLayout(null);
this.setBounds(200,200,400,400);

this.add(name);
this.add(button);
this.add(text);

this.addWindowListener(newWindowAdapter()
{
publicvoidwindowClosing(WindowEvente)
{
System.exit(-1);
}
});

button.addActionListener(this);

this.setVisible(true);
}

@Override
publicvoidactionPerformed(ActionEvente)
{
if(e.getSource()==button)
{
text.setText(name.getText());
}
}

publicstaticvoidmain(String[]args)
{
newXXFrame();
}
}

熱點內容
數據結構編譯器哪個好 發布:2025-09-18 04:33:52 瀏覽:435
ad轉換c語言 發布:2025-09-18 04:21:21 瀏覽:752
sqlserver2008設置外鍵 發布:2025-09-18 04:21:12 瀏覽:114
伺服器電腦電源管理 發布:2025-09-18 03:52:33 瀏覽:324
叉叉助手刪除腳本 發布:2025-09-18 03:21:24 瀏覽:851
深圳ug五軸編程培訓 發布:2025-09-18 03:13:35 瀏覽:197
安卓軟體殘留怎麼清理 發布:2025-09-18 03:02:02 瀏覽:345
centos7apachephp7 發布:2025-09-18 03:01:47 瀏覽:657
安卓如何實現點擊彈出列表 發布:2025-09-18 02:47:25 瀏覽:58
python文件函數 發布:2025-09-18 02:47:23 瀏覽:574