1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| import javax.swing.*; import java.util.HashMap; import java.util.Map;
public class JFramePrint {
Map<String,JFrame> map = new HashMap<>();
public void printMessage(String jframeName,String message){ JFrame jf = createJFrame(jframeName); JPanel jp=new JPanel(); JTextArea jta=new JTextArea(message); jp.add(jta); jf.add(jp); jp.updateUI(); }
public JFrame createJFrame(String name){ if(map.containsKey(name)){ return map.get(name); }else{ JFrame jf=new JFrame("窗口"); jf.setBounds(100, 100, 800, 600); jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); jf.setVisible(true); map.put(name,jf); return jf; } }
public static void main(String[] args) { JFramePrint jFramePrint = new JFramePrint(); jFramePrint.printMessage("ces","hellowold"); }
}
|