MainInitの"Capture"というaddButton押下時にThumbnailを呼び出して
ウィンドウを表示させたいのですが、どうすれば良いでしょうか?
actionlistenerで呼び出すというところまでわかりますが、何を付け足せば
良いかわかりません。
※他にもファイルがありますが省略しています。
[MainInit]
import java.awt.AWTException;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class MainInit implements ActionListener , WindowListener { //impriments(組み込む)
private JFrame mainFrame;
private Container contentPane;
private JPanel itemPanel;
private JPanel textPanel;
private JPanel buttonPanel;
private JTextField textField;
private JButton dirButton;
private JButton addButton;
private ScreenShot screenShot;
private String folderpath;
private JLabel folderlabel;
private SettingWindow settingwindow; private ItemBox itemboxtest1; private ItemBox itemboxtest2; private ItemBox itemboxtest3; private ItemBox itemboxtest4; private Thumbnail DrawPanel; public MainInit(){ mainFrame = new JFrame("エビデンスキャプチャ"); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //終了方法 mainFrame.setSize(500, 300); //ウィンドウのサイズ mainFrame.setLocationRelativeTo(null); //ウィンドウを画面の中央に表示 contentPane = mainFrame.getContentPane(); //要素、成分 メインフレームのパネルを取得 contentPane.setLayout(null); dirButton = new JButton("Dir"); //Dirボタンの作成 クラス名( ) = コンストラクタ dirButton.setBounds(20, 0, 80, 30); contentPane.add(dirButton); //コンパネにボタンを追加 addButton = new JButton("Capture"); addButton.setBounds(400, 0, 90, 60); contentPane.add(addButton); JMenuBar menubar = new JMenuBar(); JMenu menu1 = new JMenu("設定"); //メニューの生成 JMenu menu2 = new JMenu("ヘルプ"); JMenuItem menuitem1 = new JMenuItem("設定"); menubar.add(menu1); menubar.add(menu2); menu1.add(menuitem1); mainFrame.getRootPane().setJMenuBar(menubar); //メインフレームに対してメニューバーを追加 folderlabel = new JLabel(); textField = new JTextField(); //オブジェクトの作成 //dirButton = new JButton("Dir"); //Dirボタンの作成 //addButton = new JButton("Capture"); //Captureボタンの作成 //「追加」ボタンとアクション・リスナーの関連付け dirButton.addActionListener(this); dirButton.setActionCommand("Dir"); // イベントに対するコマンド文字列登録 addButton.addActionListener(this); addButton.setActionCommand("Capture"); // イベントに対するコマンド文字列登録 menuitem1.addActionListener(this); menuitem1.setActionCommand("settingwindow"); // イベントに対するコマンド文字列登録 itemPanel = new JPanel(); //上下 itemPanel.setBounds(0, 0, 500, 100); contentPane.add(itemPanel); //itemPanel.setBackground(Color.RED); textPanel = new JPanel(); //directryfield dir add textPanel.setLayout(null); contentPane.add(textPanel); textPanel.setBounds(0,80, 500, 100); //textPanel.setBackground(Color.GREEN); buttonPanel = new JPanel(); buttonPanel.setLayout(null); contentPane.add(buttonPanel); buttonPanel.setBounds(0,180,500,200); //buttonPanel.setBackground(Color.ORANGE); textPanel.add(folderlabel); folderlabel.setBounds(0, 30, 200, 30); textPanel.add(textField); textField.setBounds(320, 30, 150, 30); buttonPanel.add(dirButton); buttonPanel.add(addButton); // フォルダパス初期値 folderpath = "C:\\tmp"; // folderlabel,textFieldを初期値設定 folderlabel.setText(folderpath); textField.setText("UT_Item%d-%d-%d-%d.jpg"); mainFrame.setVisible(true); screenShot = new ScreenShot(); } // 利用者の操作に応じた処理を実装 public void actionPerformed(ActionEvent event){ // コマンド文字列を取得 String cmd = event.getActionCommand(); if(cmd.equals("Capture")){ int x = mainFrame.getX(); int y = mainFrame.getY(); // 画面キャプチャー try{ String filepath = FilePathCreate(); // 自分を消す(見えない位置に移動) mainFrame.setLocation(-1000,-1000); // 画面キャプチャ screenShot.screenCapture(filepath); // 自分を表示(元の位置に移動) mainFrame.setLocation(x, y); } catch (AWTException e){ // TODO 自動生成された catch ブロック e.printStackTrace(); } catch (IOException e){ // TODO 自動生成された catch ブロック e.printStackTrace(); } } else if(cmd.equals("Dir")) { folderpath = settingwindow.getfolderpath(); //folderpath()を取得する。 folderlabel.setText(folderpath); //folderlabelにfolderpathをセットする。 //= new Thumbnail(); } /*JFileChooser filechooser = new JFileChooser(folderpath); filechooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int selected = filechooser.showSaveDialog(this.contentPane); if (selected == JFileChooser.APPROVE_OPTION){ File file = filechooser.getSelectedFile(); folderpath = file.getAbsolutePath(); folderlabel.setText(folderpath); //else if~設定ボタンの行動 }*/ // アプリケーションの起動 public static void main(String[] args) { new MainInit(); }
}
↓ここからThumbnail
Thumbnail
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Thumbnail extends JFrame { //JFrameを継承
public Thumbnail() { add(new DrawPanel()); } public static void main(String[] A00) { Toolkit.getDefaultToolkit().setDynamicLayout(true); JFrame L00 = new Thumbnail(); L00.setTitle("イメージを拡大コピー"); L00.setDefaultCloseOperation(EXIT_ON_CLOSE); L00.setSize(300, 300); L00.setVisible(true); }
}
class DrawPanel extends JPanel {
static final String C00 = "C:/Users/yabuuchi-k/Desktop/EvidenceCapture/試験結果/UT_2-2-1.jpg";
static final int C01 = 20; // 画像のサイズ変更
Image I00;
int I01;
int I02;
public DrawPanel() { setBackground(Color.white); I00 = new ImageIcon(C00).getImage(); I01 = I00.getWidth(this); I02 = I00.getHeight(this); } public void paintComponent(Graphics A00) { super.paintComponent(A00); A00.drawString("縮小(" + C01 + "%)", 0, 10); A00.drawImage(I00, 0, 20, I01 * C01 / 100, I02 * C01 / 100, this); //縮小した画像の配置座標 }
/* public void actionPerformed(ActionEvent event){
// コマンド文字列を取得
String cmnd = event.getActionCommand();
}*/
}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2015/07/02 02:31
2015/07/02 02:39
退会済みユーザー
2015/07/02 02:49
2015/07/02 03:13
退会済みユーザー
2015/07/02 04:08
2015/07/02 04:13
退会済みユーザー
2015/07/02 04:22
2015/07/02 04:26
退会済みユーザー
2015/07/02 14:16
2015/07/02 15:46
退会済みユーザー
2015/07/03 00:06
2015/07/03 00:39
退会済みユーザー
2015/07/03 01:44