dlgtext.java

来自「程序的功能与微软的记事本功能差不多」· Java 代码 · 共 82 行

JAVA
82
字号
package jeason; 

import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*; 

public class Dlgtext extends JDialog{ 
private boolean check=false; 

JLabel text=new JLabel( ); 
JButton btnOk=new JButton( ); 
JButton btnNo=new JButton( ); 

FlowLayout flowLayout1=new FlowLayout(); 

Dlgtext(){ 
this(null,"",false); 
} 

Dlgtext(Frame frame, String title, boolean modal){ 
super(frame,title,modal); 

text.setText(" 你要保存吗? "); 
text.setSize(200,60); 

this.setSize(200,80); 
this.setModal(true); 

btnOk.setText("确定(Y)"); 
btnOk.setMnemonic('Y'); 
btnOk.setSize(100,20); 
btnOk.addActionListener(new btnOk_actionAdapter(this)); 


btnNo.setText("取消(N)"); 
btnNo.setMnemonic('N'); 
btnNo.setSize(100,20); 
btnNo.addActionListener(new btnNo_actionAdapter(this)); 


this.getContentPane().setLayout(flowLayout1); 
this.getContentPane().add(text,flowLayout1); 
this.getContentPane().add(btnOk,flowLayout1); 
this.getContentPane().add(btnNo,flowLayout1); 


} 
void btnOk_actionPerformed(ActionEvent e){ 
this.check=true; 
this.dispose(); 
this.hide(); 
} 
void btnNo_actionPerformed(ActionEvent e){ 
this.check=false; 
this.dispose(); 
this.hide(); 
} 
public boolean getCheck(){ 
return this.check; 
} 

} 

class btnOk_actionAdapter implements java.awt.event.ActionListener{ 
Dlgtext adaptee; 
btnOk_actionAdapter(Dlgtext adaptee){ 
this.adaptee=adaptee; 
} 
public void actionPerformed(ActionEvent e){ 
adaptee.btnOk_actionPerformed(e); 
} 
} 

class btnNo_actionAdapter implements java.awt.event.ActionListener{ 
Dlgtext adaptee; 
btnNo_actionAdapter(Dlgtext adaptee){ 
this.adaptee=adaptee; 
} 
public void actionPerformed(ActionEvent e){ 
adaptee.btnNo_actionPerformed(e); 
} 
} 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?