第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

java中GUI的問(wèn)題

java中GUI的問(wèn)題

慕粉3505864 2016-11-25 23:04:27
package com.project.frame;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Frame;import java.awt.HeadlessException;import java.awt.Panel;import java.awt.TextArea;import java.awt.TextField;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class MyFrame extends Frame { JLabel L_username1, L_username2, L_username3, L_username4; JTextField F_username1,F_username2, F_username3, F_username4; JButton B_submit, B_submit2; //創(chuàng)建文本區(qū) TextArea ta = new TextArea(); Panel p1 = new Panel();//輸入窗口 // 設(shè)置窗口和文字距離大小以及按鈕大小 private int x = 100; private int y = 80; private int w = 80; private int h = 30; public MyFrame() throws HeadlessException { super(); setBounds(30, 40, 530, 340);// 后面兩個(gè)值是width組件的長(zhǎng)度和height組件的高度 setLayout(null);// 設(shè)置布局管理器 setTitle("實(shí)訓(xùn)三"); // 屬性 L_username1 = new JLabel("姓名"); L_username1.setBounds(x, y, w, h); add(L_username1); L_username2 = new JLabel("性別"); L_username2.setBounds(x + w, y, w, h); add(L_username2); L_username3 = new JLabel("年齡"); L_username3.setBounds(x + 2 * w, y, w, h); add(L_username3); L_username4 = new JLabel("學(xué)號(hào)"); L_username4.setBounds(x + 3 * w, y, w, h); add(L_username4); // 方框輸入窗口 F_username1 = new JTextField(); F_username1.setBounds(x, y + h, w, h); add(F_username1); F_username2 = new JTextField(); F_username2.setBounds(x + w, y + h, w, h); add(F_username2); F_username3 = new JTextField(); F_username3.setBounds(x + 2 * w, y + h, w, h); add(F_username3); F_username4 = new JTextField(); F_username4.setBounds(x + 3 * w, y+h, w, h); add(F_username4); // 創(chuàng)建按鈕 B_submit = new JButton("提交"); B_submit.setBounds(x+4*w, y , w, h); add(B_submit); // 建立第二個(gè)按鈕 B_submit2 = new JButton("清空"); B_submit2.setBounds(x +4*w, y + h,w,h); add(B_submit2); // 按鈕事件響應(yīng) // 事件響應(yīng) B_submit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub ? ? ? ?//通過(guò)點(diǎn)擊,使得按鈕上的文字顏色改變以及輸出按鈕上的文字 // System.out.println("你點(diǎn)擊的按鈕上的文字是"+((JButton) (e.getSource())).getText() ); ? ?// ? ? ((JButton)e.getSource()).setBackground(Color.blue); ? ? ? ? ? ?ta.setText(F_username1.getText()); ? ? ? ? ? ?ta.setText(F_username2.getText()); ? ? ? ? ? ?ta.setText(F_username3.getText()); ? ? ? ? ? ?ta.setText(F_username4.getText()); } }); // 按鍵2清空 B_submit2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { F_username1.setText(""); F_username2.setText(""); F_username3.setText(""); F_username4.setText(""); } }); setVisible(true); }? ? public void launchFrame(){ ??? ? setBounds(300,300,300,300);? ? add(p1,BorderLayout.NORTH);? ? ? ? p1.add(ta);? ? }}----------------------------------------------package com.project.main;import com.project.frame.MyFrame;public class MainClass { public static void main(String[] args) { // TODO Auto-generated method stub MyFrame m =new MyFrame(); }}編譯結(jié)果如下:?jiǎn)栴}:我現(xiàn)在要通過(guò)我點(diǎn)擊“提交”,然后顯示出一個(gè)文本區(qū),文本區(qū)顯示出姓名、性別、年齡、學(xué)號(hào)。該怎么設(shè)計(jì)呢??(運(yùn)用TextArea)
查看完整描述

1 回答

?
rookie2maven

TA貢獻(xiàn)278條經(jīng)驗(yàn) 獲得超76個(gè)贊

repaint


查看完整回答
反對(duì) 回復(fù) 2016-12-01
  • 1 回答
  • 1 關(guān)注
  • 1316 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)