.NET에서 왔기 때문에 데스크톱 앱에서 Alert ()를 호출하는 데 사용됩니다. 그러나이 자바 데스크탑 응용 프로그램에서 나는 단지 “Java를 사용해 주셔서 감사합니다”라는 메시지를 경고하고 싶습니다.이 많은 고통을 겪어야합니다.
(JOptionPane 사용)
더 쉬운 방법이 있습니까?
답변
Java가 매우 장황 할 수 있음을 인정한 첫 번째 사람이 되겠지만 이것이 합리적이지 않다고 생각합니다.
JOptionPane.showMessageDialog(null, "My Goodness, this is so concise");
다음을 javax.swing.JOptionPane.showMessageDialog
사용하여 정적으로 가져 오는 경우 :
import static javax.swing.JOptionPane.showMessageDialog;
이것은 더 감소
showMessageDialog(null, "This is even shorter");
답변
JFrame이 이미 있다고 가정하면 다음과 같습니다.
JOptionPane.showMessageDialog(frame, "thank you for using java");
참조 자바 자습서 : 대화 상자 만드는 방법
을 참조하십시오를 JavaDoc을
답변
“verbosity”가 마음에 들지 않으면 항상 짧은 방법으로 코드를 감쌀 수 있습니다.
private void msgbox(String s){
JOptionPane.showMessageDialog(null, s);
}
그리고 사용법 :
msgbox("don't touch that!");
답변
스윙을 가져 오지 않아도 전화를 길게 할 수 있습니다. 그렇지 않으면 스윙 가져 오기와 간단한 호출을 사용하십시오.
JOptionPane.showMessageDialog(null, "Thank you for using Java", "Yay, java", JOptionPane.PLAIN_MESSAGE);
충분히 쉽다.
답변
“setWarningMsg ()”메소드를 호출하고 표시하려는 텍스트를 전달하십시오.
exm:- setWarningMsg("thank you for using java");
public static void setWarningMsg(String text){
Toolkit.getDefaultToolkit().beep();
JOptionPane optionPane = new JOptionPane(text,JOptionPane.WARNING_MESSAGE);
JDialog dialog = optionPane.createDialog("Warning!");
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
}
아니면 그냥 사용
JOptionPane optionPane = new JOptionPane("thank you for using java",JOptionPane.WARNING_MESSAGE);
JDialog dialog = optionPane.createDialog("Warning!");
dialog.setAlwaysOnTop(true); // to show top of all other application
dialog.setVisible(true); // to visible the dialog
JOptionPane을 사용할 수 있습니다. (WARNING_MESSAGE 또는 INFORMATION_MESSAGE 또는 ERROR_MESSAGE)
답변
