「java题目界面」java窗口标题
本篇文章给大家谈谈java题目界面,以及java窗口标题对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
求大神帮我写一下java计时器的界面的题目
package other;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Exam2 extends JFrame implements ActionListener{
/**
* @Fields serialVersionUID: TODO
*/
private static final long serialVersionUID = 1L;
private JPanel panel = new JPanel();
private JLabel timeLabel = new JLabel("00:00:00");
private JButton starButton = new JButton("开始");
private JButton stopButton = new JButton("暂停");
private JButton resetButton = new JButton("重置");
private boolean isRun = false;
private MyRunable myTimeRunable = new MyRunable();
public Exam2() {
super();
starButton.addActionListener(this);
stopButton.addActionListener(this);
resetButton.addActionListener(this);
panel.add(timeLabel);
panel.add(starButton);
panel.add(stopButton);
panel.add(resetButton);
this.add(panel);
this.setBounds(250, 250, 300, 300);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
new Thread(myTimeRunable).start();
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == starButton) {
isRun = true;
}else if(e.getSource() == stopButton) {
isRun = false;
}else if(e.getSource() == resetButton) {
myTimeRunable.reset();
}
}
private class MyRunable implements Runnable{
private int hour = 0;
private int min = 0;
private int sec = 0;
private NumberFormat format = NumberFormat.getInstance();
private String nextSecond(){
++sec;
if(sec == 60) {
++min;
sec = 0;
}
if(min == 60) {
++hour;
min = 0;
}
return currentTime();
}
private String currentTime(){
return format.format(hour)+":"+format.format(min)+":"+format.format(sec);
}
public void reset(){
synchronized(nextSecond()) {
hour = 0;
min = 0;
sec = 0;
isRun = false;
timeLabel.setText("00:00:00");
}
}
@Override
public void run() {
format.setMinimumIntegerDigits(2);
format.setGroupingUsed(false);
while(true) {
if(rootPaneCheckingEnabled) {
if(isRun) {
nextSecond();
timeLabel.setText(currentTime());
}
}
try {
Thread.sleep(1000);
}catch (InterruptedException e) {
}
}
}
}
public static void main(String[] args) {
new Exam2().setVisible(true);
}
}
java如何做选择题图形界面
要是做bs的就简单了赛,几个单选按钮就行,要是做cs的,就用swing,需要画个面板,上面添加几个JRadioButton什么的,加上事件,显示就完事了
求一道java用户界面设计题的代码
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class HelloFrame extends JFrame implements ActionListener{
public static void main(String[] args){
new HelloFrame();
}
private static final long serialVersionUID = 1L;
private int times;
protected JButton btnHello;
protected JButton btnClear;
protected JLabel lbCount;
protected JTextArea areaDisp;
public HelloFrame() {
super("Multilistener");
this.initFrame();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(320,200);
this.setVisible(true);
this.setResizable(false);
}
protected void initFrame() {
this.btnHello = new JButton("Hello!");
this.btnClear = new JButton("Clear");
this.lbCount = new JLabel("you have clicked:0 times",JLabel.CENTER);
this.areaDisp = new JTextArea();
JScrollPane pC = new JScrollPane(this.areaDisp);
JPanel pS = new JPanel();
pS.add(this.btnHello);
pS.add(this.btnClear);
this.add(this.lbCount,BorderLayout.NORTH);
this.add(pC,BorderLayout.CENTER);
this.add(pS,BorderLayout.SOUTH);
this.btnHello.addActionListener(this);
this.btnClear.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == this.btnHello){
this.areaDisp.append(this.times == 0 ? "Hello!" : "\r\nHello!");
this.lbCount.setText("you have clicked:"+(++this.times)+" times");
}
if(e.getSource() == this.btnClear){
this.times = 0;
this.areaDisp.setText("");
this.lbCount.setText("you have clicked:0 times");
}
}
}
java课程设计题目及代码是什么?
java课程设计题目及代码分别是:
1、题目:计算器。设计内容是设计一个图形界面(GUI)的计算器应用程序,完成简单的算术运算。
设计要求是设计的计算器应用程序可以完成家法、减法、乘法、除法和取余运算。且有小数点、正负号、求倒数、退格和清零功能。
2、代码:
数字按钮NumberButton类如下:
import java.awt.
import java.awt.event.
import javax.swing.
public class NumberButton extends Button.
{
int number.
public NumberButton(int number).
{
super(""+number).
this.number=number.
setForeground(Color.blue).
}
public int getNumber().
{
return number;
}
}
其它java课程设计题目及代码是:
题目:华容道。编写一个按钮的子类,使用该子类创建的对象代表华容道中的人物。通过焦点事件控制人物颜色,当人物获得焦点时颜色为蓝色,当失去焦点时颜色为灰色。
通过键盘事件和鼠标事件来实现曹操、关羽等人物的移动。当人物上发生鼠标事件或键盘事件时,如果鼠标指针的位置是在人物的下方(也就是组件的下半部分)或按下键盘的“↓“键,该人物向下移动。向左、向右和向上的移动原理类似。
代码是:
String name[]={"曹操","关羽","张","刘","马","许","兵","兵","兵","兵"}.
for(int i=0;iname.length;i++).
{
person[i]=new Person(i,name[i]).
person[i].addKeyListener(this).
person[i].addMouseListener(this).
// person[i].addFocusListener(new Person).
add(person[i]).
}
person[0].setBounds(104,54,100,100).
person[1].setBounds(104,154,100,50).
person[2].setBounds(54,154,50,100).
person[3].setBounds(204,154,50,100).
person[4].setBounds(54,54,50,100).
person[5].setBounds(204,54,50,100);
person[6].setBounds(54,254,50,50);
person[7].setBounds(204,254,50,50);
person[8].setBounds(104,204,50,50);
person[9].setBounds(154,204,50,50);
java题目界面的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java窗口标题、java题目界面的信息别忘了在本站进行查找喔。
发布于:2022-11-28,除非注明,否则均为
原创文章,转载请注明出处。