兄弟幫你寫了一個:
公司主營業(yè)務(wù):成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)推出漢陽免費(fèi)做網(wǎng)站回饋大家。
import java.awt.Button;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Random;
public class Print {
public static void main(String[] args) {
new Te();
}
}
class Te extends Frame implements ActionListener {
Color cc = Color.red;
int x = -20, y = -50;
Random r = new Random();
public Te() {
this.setLayout(null);
Button b = new Button("畫圓");
this.add(b);
b.setBounds(30,30,50,50);
b.addActionListener(this);
this.addWindowListener(new WindowAdapter () {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setBounds(200,200,500,400);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
this.cc = Color.red;
this.x = r.nextInt(400);
do {
int x1 = r.nextInt(300);
this.y = x1;
} while (this.y 50);
this.repaint();
}
@Override
public void paint(Graphics g) {
Color c = g.getColor();
g.setColor(cc);
g.drawRect(x,y,50,50);
g.setColor(c);
}
}
很簡單嘛,代碼如下
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Test {
static JFrame jf1 = new JFrame("jf1");
static JFrame jf2 = new JFrame("jf2");
static JButton jb = new JButton("click");
public static void main(String[] args) {
jf1.add(jb);
jf1.setSize(200, 200);
jf2.setSize(200, 200);
jf1.setVisible(true);
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
jf2.setVisible(true);
}
});
}
}
寫了一個很簡單的案例,可以參考和修改
import?java.awt.BorderLayout;
import?java.awt.GridLayout;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?javax.swing.JButton;
import?javax.swing.JDialog;
import?javax.swing.JFrame;
import?javax.swing.JLabel;
import?javax.swing.JTextField;
public?class?FromeDemo?extends?JFrame{
JButton?jbutton;
public?FromeDemo()?{
jbutton?=?new?JButton("彈出2個文本框");
jbutton.addActionListener(new?ActionListener()?{
@Override
public?void?actionPerformed(ActionEvent?e)?{
JDialog?jd?=?new?JDialog();
jd.setBounds(320,?180,?260,?100);
jd.setTitle("彈出文本框");
jd.getContentPane().setLayout(new?GridLayout(2,?2));
jd.add(new?JLabel("文本框一"));
jd.add(new?JTextField(80));
jd.add(new?JLabel("文本框二"));
jd.add(new?JTextField(80));
jd.setModal(true);//確保彈出的窗口在其他窗口前面
jd.setVisible(true);
}
});
add(jbutton,BorderLayout.SOUTH);
setBounds(300,?100,?320,?320);
setTitle("測試");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public?static?void?main(String?args[])?{
new?FromeDemo();
}
}
網(wǎng)站題目:java中點(diǎn)擊按鈕的代碼,java中點(diǎn)擊按鈕的代碼有哪些
標(biāo)題網(wǎng)址:http://aaarwkj.com/article46/dssgpeg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、網(wǎng)站收錄、網(wǎng)站建設(shè)、域名注冊、關(guān)鍵詞優(yōu)化、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)