コード例 #1
0
  public void tweet() {
    String textAreaText = textArea.getText();
    String textFieldText = textField.getText();
    Thread t =
        new Thread(
            new Runnable() {

              @Override
              public void run() {
                StatusUpdate status;
                if (backgroundImagePath != null) {
                  String path;
                  if (!is16_9 && convert.isSelected()) path = getConverted16_9ImagePath();
                  else path = backgroundImagePath;
                  clear();
                  status = new StatusUpdate(textAreaText + " " + textFieldText);
                  status.media(new File(path));
                } else {
                  clear();
                  status = new StatusUpdate(textAreaText + " " + textFieldText);
                }
                try {
                  twitter.updateStatus(status);
                } catch (TwitterException e) {
                  JOptionPane.showMessageDialog(Captter.this, "ツイートできませんでした");
                  return;
                }
              }

              public void clear() {
                textArea.setText("");
                textArea.requestFocus();
                imageField.setText("");
                imageField.setIcon(null);
                backgroundImagePath = null;
                backgroundImageName = null;
              }
            });
    t.start();
  }
コード例 #2
0
  /** Create the frame. */
  public Captter() {
    try {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
      SwingUtilities.updateComponentTreeUI(this);
    } catch (ClassNotFoundException
        | InstantiationException
        | IllegalAccessException
        | UnsupportedLookAndFeelException e1) {
    }

    setAlwaysOnTop(true);
    setTitle("Captter created by tao");

    Config config = new Config();
    config.loadTwitter();
    config.loadConfig();
    String[] twitterAccess = config.getTwitter();
    String CK = twitterAccess[0];
    String CS = twitterAccess[1];
    String AT = twitterAccess[2];
    String ATS = twitterAccess[3];

    Configuration jconf =
        new ConfigurationBuilder().setOAuthConsumerKey(CK).setOAuthConsumerSecret(CS).build();
    AccessToken token = new AccessToken(AT, ATS);

    twitter = new TwitterFactory(jconf).getInstance(token);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(120, 120, 420, 240);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    tweet = new JButton("Tweet(Ctrl+Enter)");
    tweet.setBounds(260, 168, 140, 30);
    tweet.addActionListener(this);
    contentPane.add(tweet);

    textArea.setBounds(0, 0, 400, 130);
    textArea.setFont(new Font("メイリオ", Font.BOLD, 20));
    textArea.setLineWrap(true);
    contentPane.add(textArea);

    textField = new HintTextField();
    textField.setBounds(0, 140, 400, 28);
    textField.setFont(new Font("メイリオ", Font.PLAIN, 12));
    textField.setHint("固定テキスト");
    contentPane.add(textField);

    JSeparator separator = new JSeparator();
    separator.setBounds(0, 130, 400, 10);
    contentPane.add(separator);

    imageField = new JLabel("");
    imageField.setBounds(0, 0, 400, 130);
    contentPane.add(imageField);

    settings = new JButton("設定");
    settings.setBounds(0, 169, 70, 30);
    settings.addActionListener(this);
    contentPane.add(settings);

    convert = new JCheckBox("convert 16:9");
    convert.setSelected(true);
    convert.setBounds(70, 170, 111, 23);
    contentPane.add(convert);

    Quick = new JCheckBox("Quick");
    Quick.setBounds(185, 170, 70, 23);
    contentPane.add(Quick);

    textArea.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            keyPress(e);
          }
        });

    addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            Config config = new Config();
            config.loadConfig();
            boolean[] removes = config.getRemoves();
            if (removes[0]) {
              File convertedDir =
                  new File(
                      new File(System.getProperty("java.class.path")).getParent() + "/converted/");
              String conDirPath = convertedDir.getPath();
              String[] convertedFiles = convertedDir.list();
              for (String s : convertedFiles) {
                if (s.endsWith(".png")) new File(conDirPath + "/" + s).delete();
              }
            }
            if (removes[1]) {
              File captureDir = new File(config.getTargetDir());
              String capDirPath = captureDir.getPath();
              String[] captureFiles = captureDir.list();
              for (String s : captureFiles) {
                if (s.endsWith(".jpg") || s.endsWith(".png") || s.endsWith(".bmp"))
                  new File(capDirPath + "/" + s).delete();
              }
            }
          }
        });

    AutoChecker ac = new AutoChecker(new File(config.getTargetDir()));
    ac.start(new File(config.getTargetDir()));
  }