兄弟幫你寫了一個(gè):
公司主營(yíng)業(yè)務(wù):成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、移動(dòng)網(wǎng)站開(kāi)發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競(jìng)爭(zhēng)能力。創(chuàng)新互聯(lián)是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開(kāi)放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來(lái)的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來(lái)驚喜。創(chuàng)新互聯(lián)推出漢陽(yáng)免費(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);
}
}
很簡(jiǎn)單嘛,代碼如下
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);
}
});
}
}
寫了一個(gè)很簡(jiǎn)單的案例,可以參考和修改
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個(gè)文本框");
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("測(cè)試");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public?static?void?main(String?args[])?{
new?FromeDemo();
}
}