求java图形化界面程序一个,可以运行,感激不尽。36volt@sohu.com
4个回答
展开全部
App.java
已发送。
代码
-----------------------------------------------------------
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
public class App extends JFrame {
MyPanel p1 = null;
MyPanel p2 = null;
MyPanel p3 = null;
MyPanel p4 = null;
public App() {
ClickListener click = new ClickListener(this);
getContentPane().setLayout(null);
p1 = new MyPanel();
p1.setBounds(307, 149, 283, 119);
p2 = new MyPanel();
p2.setBounds(307, 10, 283, 129);
p3 = new MyPanel();
p3.setBounds(12, 10, 266, 121);
p4 = new MyPanel();
p4.setBounds(12, 141, 266, 129);
this.getContentPane().add(p1);
this.getContentPane().add(p2);
this.getContentPane().add(p3);
this.getContentPane().add(p4);
JButton btnAllStart = new JButton("All Start");
btnAllStart.addActionListener(click);
btnAllStart.setBounds(82, 295, 112, 35);
getContentPane().add(btnAllStart);
JButton btnAllStop = new JButton("All Stop");
btnAllStop.addActionListener(click);
btnAllStop.setBounds(248, 295, 112, 35);
getContentPane().add(btnAllStop);
JButton btnReset = new JButton("Reset");
btnReset.addActionListener(click);
btnReset.setBounds(458, 295, 112, 35);
getContentPane().add(btnReset);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setSize(668, 411);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation((screenSize.width - this.getWidth()) / 2,
(screenSize.height - this.getHeight()) / 2);
this.setResizable(false);
this.setVisible(true);
}
public static void main(String[] args) {
new App();
}
}
class ClickListener implements ActionListener {
App ins = null;
public ClickListener(App ins) {
this.ins = ins;
}
public void actionPerformed(ActionEvent e) {
if ("All Start".equals(e.getActionCommand())) {
ins.p1.isStop = false;
ins.p2.isStop = false;
ins.p3.isStop = false;
ins.p4.isStop = false;
} else if ("All Stop".equals(e.getActionCommand())) {
ins.p1.isStop = true;
ins.p2.isStop = true;
ins.p3.isStop = true;
ins.p4.isStop = true;
} else {
ins.p1.value = 0;
ins.p2.value = 0;
ins.p3.value = 0;
ins.p4.value = 0;
ins.p1.isStop = false;
ins.p2.isStop = false;
ins.p3.isStop = false;
ins.p4.isStop = false;
}
}
}
class MyPanel extends JPanel {
public boolean isStop = false;
private JProgressBar progressBar = null;
public int value = 0;
public MyPanel() {
setLayout(null);
Listener listener = new Listener(this);
progressBar = new JProgressBar();
progressBar.setStringPainted(true);
progressBar.setBounds(26, 30, 214, 25);
add(progressBar);
JButton btnStart = new JButton("Start");
btnStart.addActionListener(listener);
btnStart.setBounds(26, 79, 91, 25);
add(btnStart);
JButton btnStop = new JButton("Stop");
btnStop.addActionListener(listener);
btnStop.setBounds(149, 79, 91, 25);
add(btnStop);
this.setSize(260, 130);
new progressCtrl().start();
}
class progressCtrl extends Thread {
public void run() {
try {
while (true) {
if (isStop) {
continue;
}
progressBar.setValue(value++);
if (value == 100) {
value = -1;
}
sleep(100);
}
} catch (Exception e) {
}
}
}
}
class Listener implements ActionListener {
MyPanel ins = null;
public Listener(MyPanel ins) {
this.ins = ins;
}
public void actionPerformed(ActionEvent e) {
if ("Start".equals(e.getActionCommand())) {
ins.isStop = false;
} else {
ins.isStop = true;
}
}
}
已发送。
代码
-----------------------------------------------------------
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
public class App extends JFrame {
MyPanel p1 = null;
MyPanel p2 = null;
MyPanel p3 = null;
MyPanel p4 = null;
public App() {
ClickListener click = new ClickListener(this);
getContentPane().setLayout(null);
p1 = new MyPanel();
p1.setBounds(307, 149, 283, 119);
p2 = new MyPanel();
p2.setBounds(307, 10, 283, 129);
p3 = new MyPanel();
p3.setBounds(12, 10, 266, 121);
p4 = new MyPanel();
p4.setBounds(12, 141, 266, 129);
this.getContentPane().add(p1);
this.getContentPane().add(p2);
this.getContentPane().add(p3);
this.getContentPane().add(p4);
JButton btnAllStart = new JButton("All Start");
btnAllStart.addActionListener(click);
btnAllStart.setBounds(82, 295, 112, 35);
getContentPane().add(btnAllStart);
JButton btnAllStop = new JButton("All Stop");
btnAllStop.addActionListener(click);
btnAllStop.setBounds(248, 295, 112, 35);
getContentPane().add(btnAllStop);
JButton btnReset = new JButton("Reset");
btnReset.addActionListener(click);
btnReset.setBounds(458, 295, 112, 35);
getContentPane().add(btnReset);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setSize(668, 411);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation((screenSize.width - this.getWidth()) / 2,
(screenSize.height - this.getHeight()) / 2);
this.setResizable(false);
this.setVisible(true);
}
public static void main(String[] args) {
new App();
}
}
class ClickListener implements ActionListener {
App ins = null;
public ClickListener(App ins) {
this.ins = ins;
}
public void actionPerformed(ActionEvent e) {
if ("All Start".equals(e.getActionCommand())) {
ins.p1.isStop = false;
ins.p2.isStop = false;
ins.p3.isStop = false;
ins.p4.isStop = false;
} else if ("All Stop".equals(e.getActionCommand())) {
ins.p1.isStop = true;
ins.p2.isStop = true;
ins.p3.isStop = true;
ins.p4.isStop = true;
} else {
ins.p1.value = 0;
ins.p2.value = 0;
ins.p3.value = 0;
ins.p4.value = 0;
ins.p1.isStop = false;
ins.p2.isStop = false;
ins.p3.isStop = false;
ins.p4.isStop = false;
}
}
}
class MyPanel extends JPanel {
public boolean isStop = false;
private JProgressBar progressBar = null;
public int value = 0;
public MyPanel() {
setLayout(null);
Listener listener = new Listener(this);
progressBar = new JProgressBar();
progressBar.setStringPainted(true);
progressBar.setBounds(26, 30, 214, 25);
add(progressBar);
JButton btnStart = new JButton("Start");
btnStart.addActionListener(listener);
btnStart.setBounds(26, 79, 91, 25);
add(btnStart);
JButton btnStop = new JButton("Stop");
btnStop.addActionListener(listener);
btnStop.setBounds(149, 79, 91, 25);
add(btnStop);
this.setSize(260, 130);
new progressCtrl().start();
}
class progressCtrl extends Thread {
public void run() {
try {
while (true) {
if (isStop) {
continue;
}
progressBar.setValue(value++);
if (value == 100) {
value = -1;
}
sleep(100);
}
} catch (Exception e) {
}
}
}
}
class Listener implements ActionListener {
MyPanel ins = null;
public Listener(MyPanel ins) {
this.ins = ins;
}
public void actionPerformed(ActionEvent e) {
if ("Start".equals(e.getActionCommand())) {
ins.isStop = false;
} else {
ins.isStop = true;
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2012-01-04
展开全部
什么样的程序
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
怎么没有你提供的邮箱啊
追问
36volt@sohu.com
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
邮箱不存在
追问
刚确认了一下,好久没用被收回了,刚重新激活了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询