예제 #1
1
파일: Game.java 프로젝트: cpetosky/o2d-lib
  // --------------------------------actionConnect------------------------------
  private void actionConnect() {
    if (oParty == null) {
      JOptionPane.showMessageDialog(frame, "Make a party before trying to connect.");
      return;
    }

    String[] oResults = (String[]) DialogManager.show(DialogManager.CONNECT, frame);

    if (oResults[DialogManager.RETURN_IP].equals("cancel")) return;

    lblStatus3.setText("Connecting...");
    try {
      oConn.connect(
          oResults[DialogManager.RETURN_IP], Integer.parseInt(oResults[DialogManager.RETURN_PORT]));
    } catch (UnknownHostException e) {
      JOptionPane.showMessageDialog(
          frame,
          "The IP of the host cannot be determined.",
          "Unknown Host Exception",
          JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          frame, e.getMessage(), "Input/Output Exception", JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    }
    echo("Connected to opponent!");

    tConn = new Thread(oConn, "conn");
    tConn.start();
    tMain = new Thread(this, "main");
    tMain.start();
  }
  /** Simple test program. */
  public static void main(String[] args) {
    final JFrame frame = new JFrame("Testing AddPersonDialog");
    JButton button = new JButton("Click me");
    button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            FamilyTree tree = new FamilyTree();
            AddPersonDialog dialog = new AddPersonDialog(frame, tree);
            dialog.pack();
            dialog.setLocationRelativeTo(frame);
            dialog.setVisible(true);

            Person newPerson = dialog.getPerson();
            if (newPerson != null) {
              tree.addPerson(newPerson);
              PrettyPrinter pretty = new PrettyPrinter(new PrintWriter(System.out, true));
              pretty.dump(tree);
            }
          }
        });
    frame.getContentPane().add(button);

    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(1);
          }
        });
    frame.pack();
    frame.setVisible(true);
  }
예제 #3
0
 public void setUpGui() {
   m1 = new MyDrawPanel();
   f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   f.setContentPane(m1);
   f.setBounds(30, 30, 300, 300);
   f.setVisible(true);
 } // quit meth
  public void openCaptureWindow() {
    if (framenr - lastcapture_framenr < number_of_frames_before_cwopen) {
      return;
    }

    // Capture Window
    cw.setVisible(true);
    cw.toFront();

    // Timer for closing the capturewindow
    TimerTask task =
        new TimerTask() {

          @Override
          public void run() {
            EventQueue.invokeLater(
                new Runnable() {
                  public void run() {
                    System.out.println("Closing cw...");
                    cw.setVisible(false);
                    cwText.setText(""); // Empty text in case there is a text
                  }
                });
          }
        };
    cwTimer = new Timer();
    cwTimer.schedule(task, number_of_second_capturewindow * 1000);
  }
  public static void main(String[] args) {

    StringBuffer result = new StringBuffer("<html><body><h1>Fibonacci Sequence</h1><ol>");

    long f1 = 0;
    long f2 = 1;

    for (int i = 0; i < 50; i++) {
      result.append("<li>");
      result.append(f1);
      long temp = f2;
      f2 = f1 + f2;
      f1 = temp;
    }

    result.append("</ol></body></html>");

    JEditorPane jep = new JEditorPane("text/html", result.toString());
    jep.setEditable(false);

    //  new FibonocciRectangles().execute();
    JScrollPane scrollPane = new JScrollPane(jep);
    JFrame f = new JFrame("Fibonacci Sequence");
    f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    f.setContentPane(scrollPane);
    f.setSize(512, 342);
    EventQueue.invokeLater(new FrameShower(f));
  }
예제 #6
0
  public void pdfRead() {
    try {
      String INPUTFILE = "example_2.pdf";
      File file = new File(INPUTFILE);
      RandomAccessFile raf = new RandomAccessFile(file, "r");
      FileChannel channel = raf.getChannel();
      ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
      PDFFile pdffile = new PDFFile(buf);

      // draw the first page to an image
      PDFPage page = pdffile.getPage(0);

      // get the width and height for the doc at the default zoom
      Rectangle rect =
          new Rectangle(0, 0, (int) page.getBBox().getWidth(), (int) page.getBBox().getHeight());

      // generate the image
      Image img =
          page.getImage(
              rect.width,
              rect.height, // width & height
              rect, // clip rect
              null, // null for the ImageObserver
              true, // fill background with white
              true // block until drawing is done
              );

      frame.getContentPane().add(new JLabel(new ImageIcon(img)));

      frame.pack();
      frame.setSize(600, 700);
    } catch (Exception e) {
      System.out.println(e);
    }
  }
예제 #7
0
 public void create() {
   JFrame frame = new JFrame();
   frame.getContentPane().add(new JScrollPane(jgraph));
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.pack();
   frame.setVisible(true);
 }
예제 #8
0
  private void _displayRespStrInFrame() {

    final JFrame frame = new JFrame("Google Static Map - Error");
    GUIUtils.setAppIcon(frame, "69.png");
    // frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    JTextArea response = new JTextArea(_respStr, 25, 80);
    response.addMouseListener(
        new MouseListener() {
          public void mouseClicked(MouseEvent e) {}

          public void mousePressed(MouseEvent e) {
            /*frame.dispose();*/
          }

          public void mouseReleased(MouseEvent e) {}

          public void mouseEntered(MouseEvent e) {}

          public void mouseExited(MouseEvent e) {}
        });

    frame.setContentPane(new JScrollPane(response));
    frame.pack();

    GUIUtils.centerOnScreen(frame);
    frame.setVisible(true);
  }
예제 #9
0
  /**
   * Load a file of a particular type. It's a pretty standard helper function, which uses DarwinCSV
   * and setCurrentCSV(...) to make file loading happen with messaging and whatnot. We can also
   * reset the display: just call loadFile(null).
   *
   * @param file The file to load.
   * @param type The type of file (see DarwinCSV's constants).
   */
  private void loadFile(File file, short type) {
    // If the file was reset, reset the display and keep going.
    if (file == null) {
      mainFrame.setTitle(basicTitle);
      setCurrentCSV(null);
      return;
    }

    // Load up a new DarwinCSV and set current CSV.
    try {
      setCurrentCSV(new DarwinCSV(file, type));

    } catch (IOException ex) {
      MessageBox.messageBox(
          mainFrame,
          "Could not read file '" + file + "'",
          "Unable to read file '" + file + "': " + ex);
    }

    // Set the main frame title, based on the filename and the index.
    mainFrame.setTitle(
        basicTitle
            + ": "
            + file.getName()
            + " ("
            + String.format("%,d", currentCSV.getRowIndex().getRowCount())
            + " rows)");
  }
예제 #10
0
  public void mustMakeChoice() {
    final JFrame frame = new JFrame("Must specify one option");

    JPanel panel = new JPanel();
    JLabel exitLabel = new JLabel("Must specify one option");
    JButton okButton = new JButton("Continue");
    okButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            frame.dispose();
          }
        });

    panel.setBorder(
        BorderFactory.createEmptyBorder(
            30, // top
            30, // left
            10, // bottom
            30) // right
        );
    panel.setLayout(new GridLayout(0, 1));

    panel.add(exitLabel);
    panel.add(okButton);
    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);
  }
  public static void main(String[] args) {
    ArrayList<Pattern> patterns = new ArrayList<Pattern>();
    ArrayList<Cut> cuts;
    ArrayList<Garment> garments;

    patterns.add(new Pattern(2, 2, 1, "Tie"));
    patterns.add(new Pattern(2, 6, 4, "Skirt"));
    patterns.add(new Pattern(4, 2, 3, "Blouse"));
    patterns.add(new Pattern(5, 3, 5, "Dress"));
    int width = 30;
    int height = 15;
    ClothCutter cutter = new ClothCutter(width, height, patterns);
    System.out.println("Optimized value: " + cutter.optimize());
    cuts = cutter.getCuts();
    garments = cutter.getGarments();

    ClothPanel panel = new ClothPanel(width, height);
    JFrame frame = new JFrame("A luxurious bolt of fabric");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);
    sleep(1000);
    for (int i = 0; i < cuts.size(); i++) {
      panel.drawCut(cuts.get(i));
      sleep(100);
    }
    for (int i = 0; i < garments.size(); i++) {
      System.out.println(garments.get(i));
      panel.drawGarment(garments.get(i));
      sleep(100);
    }
  }
예제 #12
0
  // Add a test case to testBox and tests array.
  private void addTest() {

    // Set up the frame for the file chooser.
    final JFrame appframe = new JFrame("Select Application");
    appframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    Container contentPane = appframe.getContentPane();
    JFileChooser fileChooser = new JFileChooser(".");

    // Only let you select directories and add chooser to pane.
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    contentPane.add(fileChooser, BorderLayout.CENTER);

    // Make a new action listener for the file chooser.
    ActionListener actionListener =
        new ActionListener() {

          public void actionPerformed(ActionEvent actionEvent) {

            // Get the information to check if the file chosen is valid.
            JFileChooser theFileChooser = (JFileChooser) actionEvent.getSource();
            String command = actionEvent.getActionCommand();

            // If the user cancels selecting a program.
            if (command.equals(JFileChooser.CANCEL_SELECTION)) {
              appframe.setVisible(false);
              appframe.dispose();
              return;
            }

            // If the file chosen is valid.
            if (command.equals(JFileChooser.APPROVE_SELECTION)) {
              // Retrieve the selected file and ask for the main class name.
              File f = theFileChooser.getSelectedFile();

              // Obtain the file URL.
              String fileURL = null;
              fileURL = f.getAbsolutePath();

              // Add a checkbox to the testing check pane.
              JCheckBox newTest = new JCheckBox(fileURL, true);
              testBox.setEditable(true);
              testBox.add(newTest);
              testBox.repaint();
              testBox.setEditable(false);
              // Add the test to the list of tests.
              tests.add(newTest);

              // Make the file chooser disappear.
              appframe.setVisible(false);
              appframe.dispose();
            }
          }
        };

    // Add the action listener created above to file chooser, display it.
    fileChooser.addActionListener(actionListener);
    appframe.pack();
    appframe.setVisible(true);
  }
예제 #13
0
  // Constructor
  public FileWindow() {

    myWindow = new JFrame("New File");
    myWindow.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    Container contentPane = myWindow.getContentPane();
    contentPane.setLayout(new BorderLayout());

    saveButton = new JButton("Save File");
    saveButton.setSelected(false);
    saveButton.setActionCommand("save");
    saveButton.setMnemonic('S');
    // saveButton.addActionListener(new ScriptWindowButtonListener());

    clearButton = new JButton("Clear Contents");
    clearButton.setSelected(false);
    clearButton.setActionCommand("clear");
    clearButton.setMnemonic('B');
    clearButton.addActionListener(new ScriptWindowButtonListener());

    cancelButton = new JButton("Quit");
    cancelButton.setSelected(false);
    cancelButton.setActionCommand("quit");
    cancelButton.setMnemonic('Q');
    cancelButton.addActionListener(new ScriptWindowButtonListener());

    //		loadButton = new JButton("Load Script");
    //		loadButton.setSelected(false);
    //		loadButton.setActionCommand("load");
    //		loadButton.setMnemonic('L');
    //		loadButton.addActionListener(new ScriptWindowButtonListener());
    //
    //		runButton = new JButton("Run Script");
    //		runButton.setSelected(false);
    //		runButton.setActionCommand("run");
    //		runButton.setMnemonic('L');
    //		runButton.addActionListener(new ScriptWindowButtonListener());

    buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout(1, 0));
    // buttonPanel.add(runButton);
    buttonPanel.add(saveButton);
    // buttonPanel.add(loadButton);
    buttonPanel.add(clearButton);
    // buttonPanel.add(cancelButton);

    fileChooser = new JFileChooser();

    scriptArea = new JTextArea(35, 30);
    JScrollPane scroller = new JScrollPane(scriptArea);

    textHolder = new JPanel();
    textHolder.setLayout(new BorderLayout());
    textHolder.add(scroller, BorderLayout.CENTER);

    contentPane.add(buttonPanel, BorderLayout.NORTH);
    contentPane.add(textHolder, BorderLayout.CENTER);
    myWindow.pack();
  }
예제 #14
0
파일: Chart.java 프로젝트: feihugis/NetCDF
  public static void main(String[] args) {
    Chart shc = new Chart("C:/TEMP/table.csv");

    JFrame frame = new JFrame("Stock History Chart for " + shc.getSymbol());
    frame.getContentPane().add(shc, BorderLayout.CENTER);
    frame.setSize(640, 480);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
예제 #15
0
 public static void main(String[] argv) throws NoSuchMethodException {
   f = new JFrame();
   Container c = f.getContentPane();
   c.setLayout(new BorderLayout());
   c.add(new WordListScreen(null), BorderLayout.CENTER);
   f.pack();
   f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   showFrame(true);
 }
예제 #16
0
 // creates the JFrame, and puts first room onto panel
 public static void main(String[] s) throws IOException {
   JFrame f = new JFrame();
   f.getContentPane().add(new Adventure());
   f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   f.pack();
   f.setVisible(true);
   Environment Layout = new Environment();
   wallLayout = Layout.walls(mapX, mapY);
 }
예제 #17
0
 /**
  * This method creates a JFrame where everything will be displayed INPUT (parameters): none OUTOUT
  * (return): none
  */
 public static void createAndShowGUI() {
   JFrame frame =
       new JFrame("Black Jack"); // title of the JFrame
   BlackJack demo = new BlackJack(); // create and set up the content pane
   frame.setContentPane(demo.createContentPane());
   frame.setDefaultCloseOperation(
       JFrame.EXIT_ON_CLOSE); // what happens if the user presses the x button
   frame.setSize(950, 760);
   frame.setVisible(true); // ensure frame is visible
 }
예제 #18
0
  public ArcViewer() {

    JFrame frame = new JFrame("ArcViewer v.0.9");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    frame.add("Center", this);
    frame.setSize(900, 600);
    frame.setVisible(true);

    init();
  }
예제 #19
0
 /** Leave Group and close JWhiteBoard */
 public void stop() {
   if (!noChannel) {
     try {
       channel.close();
     } catch (Exception ex) {
       System.err.println(ex);
     }
   }
   mainFrame.setVisible(false);
   mainFrame.dispose();
 }
예제 #20
0
 public void actionPerformed(ActionEvent e) {
   if (!datapanel.isInitialized()) {
     return;
   }
   datapanel.refreshData();
   panel.setDisplayPlot(true);
   panel.update(panel.getGraphics());
   frame.setSize(700, 600);
   frame.setVisible(true);
   frame.pack();
 }
예제 #21
0
 private void showIDE(boolean show) {
   SikuliIDE.getInstance().setVisible(show);
   if (show) {
     addMinComponentsToPane(mainPane);
   } else {
     addMinComponentsToPane(minPane);
     Container con = minFrame.getContentPane();
     con.add(minPane);
     minFrame.doLayout();
   }
   minFrame.setVisible(!show);
 }
예제 #22
0
  public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException {

    JFrame jf = new JFrame();

    AttributesPanel colpal = new AttributesPanel();
    colpal.setEntity(new FrameFact("hola"));
    colpal.setEntity(new FrameFact("hola"));
    jf.getContentPane().add(colpal);
    jf.pack();
    jf.show();
    jf.pack();
  }
예제 #23
0
  private void initialize() {
    frame = new JFrame();
    frame.setSize(600, 700);
    //		frame.getContentPane().setLayout(null);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //		frame.setResizable(false);
    frame.setTitle("PDF");
    //		frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    //        frame.pack();

  }
  /**
   * Create the GUI and show it. For thread safety, this method should be invoked from the event
   * dispatch thread.
   */
  private static void createAndShowGUI() {
    // Create and set up the window.
    JFrame frame = new JFrame("FileChooserDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Add content to the window.
    frame.add(new FileChooserDemo());

    // Display the window.
    frame.pack();
    frame.setVisible(true);
  }
예제 #25
0
 private void initMinFrame() {
   minFrame = new JFrame("Sikuli Test");
   minFrame.setAlwaysOnTop(true);
   minFrame.setSize(255, 85);
   minFrame.getRootPane().putClientProperty("Window.alpha", new Float(0.7f));
   /*
   Container con = minFrame.getContentPane();
   con.add(minPane);
   minFrame.doLayout();
   minFrame.setVisible(true);
   */
 }
  /**
   * Create the GUI and show it. For thread safety, this method should be invoked from the event
   * dispatch thread.
   */
  private static void createAndShowGUI() {
    // Create and set up the window.
    JFrame frame = new JFrame("Viettel Enterprise Platform - Module Friendlizer");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Add content to the window.
    frame.add(new GuiFriendlizerApp());

    // Display the window.
    frame.pack();
    frame.setVisible(true);
  }
예제 #27
0
 public void go() {
   JFrame frame = new JFrame("JFrame");
   JPanel mainPanel = new JPanel();
   outgoing = new JTextField(20);
   JButton sendButton = new JButton("send");
   sendButton.addActionListener(new SendButtonListener());
   mainPanel.add(outgoing);
   mainPanel.add(sendButton);
   frame.getContentPane().add(BorderLayout.CENTER, mainPanel);
   setUpNetworking();
   frame.setSize(400, 500);
   frame.setVisible(true);
 }
예제 #28
0
 // --------初始化界面的方法---------
 public void init() {
   JPanel top = new JPanel();
   top.add(new JLabel("输入查询语句:"));
   top.add(sqlField);
   top.add(execBn);
   // 为执行按钮、单行文本框添加事件监听器
   execBn.addActionListener(new ExceListener());
   sqlField.addActionListener(new ExceListener());
   jf.add(top, BorderLayout.NORTH);
   jf.setSize(680, 480);
   jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   jf.setVisible(true);
 }
  public void go() {
    frame = new JFrame("Quiz Card Player");
    JPanel mainPanel = new JPanel();
    Font bigFont = new Font("sanserif", Font.BOLD, 24);

    display = new JTextArea(10, 20);
    display.setFont(bigFont);
    display.setLineWrap(true);
    display.setEditable(false);

    JScrollPane qScroller = new JScrollPane(display);
    qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

    nextButton = new JButton("Show Questions");
    nextButton.addActionListener(new NextCardListener());

    mainPanel.add(qScroller);
    mainPanel.add(nextButton);

    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu("File");
    JMenuItem loadMenuItem = new JMenuItem("Load Card Set");
    loadMenuItem.addActionListener(new OpenMenuListener());
    fileMenu.add(loadMenuItem);
    menuBar.add(fileMenu);

    frame.setJMenuBar(menuBar);
    frame.getContentPane().add(BorderLayout.CENTER, mainPanel);
    frame.setSize(640, 500);
    frame.setVisible(true);
  }
예제 #30
-1
  public void go() {
    // build gui

    frame = new JFrame("Quiz Card Buider");
    JPanel mainPanel = new JPanel();
    Font bigFont = new Font("sanserif", Font.BOLD, 24);
    question = new JTextArea(6, 20);
    question.setLineWrap(true);
    question.setWrapStyleWord(true);
    question.setFont(bigFont);

    JScrollPane qScroller = new JScrollPane(question);
    qScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    qScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

    answer = new JTextArea(6, 20);
    answer.setLineWrap(true);
    answer.setWrapStyleWord(true);
    answer.setFont(bigFont);

    JScrollPane aScroller = new JScrollPane(question);
    aScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    aScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

    JButton nextButton = new JButton("Next Card");

    cardList = new ArrayList<QuizCard>();

    JLabel qLabel = new JLabel("Question");
    JLabel aLabel = new JLabel("Answer");

    mainPanel.add(qLabel);
    mainPanel.add(qScroller);
    mainPanel.add(aLabel);
    mainPanel.add(aScroller);
    mainPanel.add(nextButton);

    nextButton.addActionListener(new NextCardListener());

    JMenuBar menuBar = new JMenuBar();

    JMenu fileMenu = new JMenu("File");

    JMenuItem newMenuItem = new JMenuItem("New");
    JMenuItem saveMenuItem = new JMenuItem("Save");
    newMenuItem.addActionListener(new NewMenuListener());
    saveMenuItem.addActionListener(new SaveMenuListener());

    fileMenu.add(newMenuItem);
    fileMenu.add(saveMenuItem);
    menuBar.add(fileMenu);
    frame.setJMenuBar(menuBar);
    frame.getContentPane().add(BorderLayout.CENTER, mainPanel);
    frame.setSize(500, 600);
    frame.setVisible(true);
    // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  }