📄 commentdialog.java
字号:
package abchr.gui;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class CommentDialog extends JDialog {
private JTextArea textArea=new JTextArea();
private boolean ok=false;
private CommentDialogListener listener=null;
public CommentDialog() {
super(Main.frame,"Add Comments...",true);
this.setResizable(false);
this.setSize(300,250);
this.getContentPane().setLayout(new BorderLayout());
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
this.getContentPane().add(new JScrollPane(textArea),BorderLayout.CENTER);
JPanel bottomPanel=new JPanel(new FlowLayout(FlowLayout.RIGHT));
JButton okButton=new JButton("OK");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){okPressed();}
});
JButton cancelButton=new JButton("Cancel");
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){cancelPressed();}
});
bottomPanel.add(cancelButton);
bottomPanel.add(okButton);
this.getRootPane().setDefaultButton(okButton);
this.getContentPane().add(bottomPanel,BorderLayout.SOUTH);
}
private void cancelPressed(){ok=false;this.setVisible(false);}
private void okPressed(){ok=true;this.setVisible(false);if(listener!=null){listener.dialogClosed(this,textArea.getText());}}
public String showDialogModal(String comment) {
if(this.isShowing()){return null;}
this.listener=null;
this.setModal(true);
textArea.setText(comment);
ok=false;
this.setLocation(Main.frame.getX()+10,Main.frame.getY()+10);
this.setVisible(true);
if(ok){return textArea.getText();}else{return null;}
}
public String showDialogModal() {
return showDialogModal(textArea.getText());
}
public boolean showDialogModeless(String comment,CommentDialogListener listener) {
if(this.isShowing()){return false;}
this.listener=listener;
this.setModal(false);
textArea.setText(comment);
ok=false;
this.setLocation(Main.frame.getX()+10,Main.frame.getY()+10);
this.setVisible(true);
return true;
}
public boolean showDialogModeless(CommentDialogListener listener) {
return showDialogModeless(textArea.getText(),listener);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -