我正在使用Eclipse Photon 2018并使用Java制作一个简单的项目。我开始使用JOptionPane
,由于某种原因 - 尺寸很小,如下图所示:
我的代码:
main.Java:
public class Main {
public static void main(String[] args) {
Messageable ui = new GrapghicalUI();
String res = ui.getString("what is your name? ");
ui.showMessage("hi" +res);
}
}
consul E UI.Java:
import java.util.Scanner;
public class ConsoleUI implements Messageable{
private Scanner s = new Scanner(System.in);
@Override
public void showMessage(String str) {
System.out.println(str);
}
@Override
public String getString(String msg) {
System.out.println(msg);
return s.next();
}
}
graphical UI.Java:
import javax.swing.JOptionPane;
public class GrapghicalUI implements Messageable {
@Override
public void showMessage(String str) {
JOptionPane.showMessageDialog(null, str);
}
@Override
public String getString(String msg) {
return JOptionPane.showInputDialog(msg);
}
}
Messageable:
public interface Messageable {
void showMessage(String str);
String getString(String msg);
}