import javaawteventActionListener;
import javaxswingJFrame;
import javaxswingJMenu;
import javaxswingJMenuBar;
import javaxswingJMenuItem;
public classTest extends JFrame implements ActionListener{
public Test(){
setDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
setVisible(true);
setBounds(200, 100, 300, 400);
JMenuBar jMenuBar=new JMenuBar();
JMenu jMenu=new JMenu(" *** 作");
JMenuItem jMenuItem=new JMenuItem("设置运行时间");
setJMenuBar(jMenuBar);
jMenuBaradd(jMenu);
jMenuadd(jMenuItem);
jMenuItemaddActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
new TimerFrame();
}
public static void main(String[]args){
Systemoutprintln("gg");
new Test();
}
}
import javaawtFlowLayout;
import javaawteventActionEvent;
import javaawteventActionListener;
import javaxswingJButton;
import javaxswingJFrame;
import javaxswingJLabel;
import javaxswingJTextField;
import javaxswingTimer;
public class TimerFrame extends JFrame implements ActionListener{
JButton jButton=new JButton("确定");
long time=0;
Timer timer;
int m;
JTextField jField=new JTextField(10);
public TimerFrame(){
setLayout(new FlowLayout());
timer=new Timer(1000,this);
setVisible(true);
setLocation(400,300);
add(new JLabel("设置:"));
add(jField);
add(new JLabel("秒后"));
add(jButton);
jButtonaddActionListener(this);
pack();
}
@Override
public void actionPerformed(ActionEvent e) {
String string=egetActionCommand();
if(string!=null&&stringequals("确定"))
{
timerstart();
thisdispose();
m=IntegerparseInt(jFieldgetText());
}
else{
if(time==m)
Systemexit(0);
time++;
}
}
}
要求是达到了。自己完善设置时分秒后退出,判断输入的是否有效等等。有什么疑问可hi我后追问
如果模态对话框不关闭,无法 *** 作主窗体。如果非模态对话框不关闭,仍然可以 *** 作主窗体。
//构造模态对话框
final Dialog d = new Dialog(this, "模态对话框", true);
//构造非模态对话框
final Dialog d = new Dialog(this, "模态对话框", false);
样例程序如下:
import javaawtDialog;import javaawtFlowLayout;
import javaawteventActionEvent;
import javaawteventActionListener;
import javaawteventWindowAdapter;
import javaawteventWindowEvent;
import javaxswingJButton;
import javaxswingJFrame;
public class Main extends JFrame implements ActionListener {
JButton btnModel, btnNonModel;
public Main() {
super("对话框");
thissetLayout(new FlowLayout());
btnModel = new JButton("打开模态对话框");
btnNonModel = new JButton("打开非模态对话框");
thisadd(btnModel);
thisadd(btnNonModel);
btnModeladdActionListener(this);
btnNonModeladdActionListener(this);
thissetSize(200, 200);
thissetVisible(true);
thissetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Main();
}
@Override
public void actionPerformed(ActionEvent arg0) {
JButton btn = (JButton) arg0getSource();
if(btn == btnModel) { //打开模态对话框
final Dialog d = new Dialog(this, "模态对话框", true);
dsetSize(800, 600);
daddWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
dsetVisible(false);
}
});
dsetVisible(true);
}
else if(btn == btnNonModel) { //打开非模态对话框
final Dialog d = new Dialog(this, "非模态对话框", false);
dsetSize(800, 600);
daddWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
dsetVisible(false);
}
});
dsetVisible(true);
}
}
}
可以用java编写
微信小程序提供了很丰富的组件和接口,他带了一套半Vue半React的“语言”,开发如果你是前端正好又熟悉Vue或React的话,那么就是你的菜。
public void mouseReleased(MouseEvent e){
if(egetButton() == MouseEventBUTTON3)//点击右键
popUpMenushow(editMenu, egetX(), egetY());
//popUpMenu是一个JPopupMenu editMenu是一个JMenu
//egetX(), egetY()是获得鼠标点击的坐标 在点击的地方d出一个 editMenu,editMenu中的 内容自己添加
}
public void mouseClicked(MouseEvent e) {
if(egetButton() == MouseEventBUTTON1)//点击鼠标左键
popUpMenusetVisible(false);//d出菜单消失
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)