質問編集履歴
2
必要なソースコードを追加しました.Thumbnailクラスの I00 = new ImageIcon(filepath).getImage();でエラーが発生しています。
test
CHANGED
File without changes
|
test
CHANGED
@@ -492,107 +492,71 @@
|
|
492
492
|
|
493
493
|
|
494
494
|
|
495
|
-
|
495
|
+
Thumbnail
|
496
496
|
|
497
497
|
```lang-java
|
498
498
|
|
499
|
-
public class
|
499
|
+
public class Thumbnail extends JFrame { //JFrameを継承
|
500
|
-
|
501
|
-
|
500
|
+
|
502
|
-
|
503
|
-
|
501
|
+
|
504
|
-
|
505
|
-
|
502
|
+
|
506
|
-
|
503
|
+
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
|
508
|
+
|
507
|
-
|
509
|
+
public Thumbnail(File filepath) {
|
508
|
-
|
509
|
-
|
510
|
+
|
510
|
-
|
511
|
-
|
511
|
+
add(new DrawPanel(filepath));
|
512
|
-
|
513
|
-
|
514
|
-
|
512
|
+
|
515
|
-
|
513
|
+
setTitle("イメージを拡大コピー");
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
514
|
+
|
524
|
-
|
525
|
-
|
515
|
+
//setDefaultCloseOperation(EXIT_ON_CLOSE);
|
526
|
-
|
527
|
-
|
516
|
+
|
528
|
-
|
529
|
-
gbc.gridx = x;
|
530
|
-
|
531
|
-
gbc.gridy = y;
|
532
|
-
|
533
|
-
|
517
|
+
setSize(350, 350);
|
534
|
-
|
518
|
+
|
535
|
-
|
519
|
+
setVisible(true);
|
536
|
-
|
537
|
-
gbl.setConstraints((Component) itemobject, gbc);
|
538
|
-
|
539
|
-
add((Component) itemobject);
|
540
520
|
|
541
521
|
}
|
542
522
|
|
523
|
+
|
524
|
+
|
525
|
+
|
526
|
+
|
543
|
-
|
527
|
+
}
|
528
|
+
|
529
|
+
|
530
|
+
|
544
|
-
|
531
|
+
class DrawPanel extends JPanel {
|
532
|
+
|
533
|
+
|
534
|
+
|
535
|
+
static final int C01 = 30; // 画像のサイズ変更
|
536
|
+
|
537
|
+
Image I00;
|
538
|
+
|
539
|
+
int I01;
|
540
|
+
|
541
|
+
int I02;
|
542
|
+
|
543
|
+
|
544
|
+
|
545
|
+
|
546
|
+
|
547
|
+
|
548
|
+
|
545
|
-
public
|
549
|
+
public DrawPanel(File filepath) {
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
+
|
550
|
-
|
551
|
-
|
551
|
+
setBackground(Color.white);
|
552
|
-
|
553
|
-
|
554
|
-
|
552
|
+
|
553
|
+
|
554
|
+
|
555
|
-
|
555
|
+
I00 = new ImageIcon(filepath).getImage();
|
556
|
-
|
557
|
-
|
556
|
+
|
558
|
-
|
559
|
-
itemField.setFocusable(false); //入力制限
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
upButton = new JButton("↑"); //upButtonオブジェクトを作成し、↑を代入する。
|
564
|
-
|
565
|
-
downButton = new JButton("↓"); //downButtonオブジェクトを作成し、↓を代入する。
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
upButton.setActionCommand("upButton");
|
574
|
-
|
575
|
-
upButton.addActionListener(this); //アクションイベントを受け取れるようになる。
|
576
|
-
|
577
|
-
downButton.setActionCommand("downButton");
|
578
|
-
|
579
|
-
|
557
|
+
I01 = I00.getWidth(this);
|
580
|
-
|
581
|
-
|
582
|
-
|
558
|
+
|
583
|
-
|
559
|
+
I02 = I00.getHeight(this);
|
584
|
-
|
585
|
-
addButton(itemField, 0, 0, 1, 2); // (0, 0) 幅=1, 高さ=3
|
586
|
-
|
587
|
-
addButton(upButton, 1, 0, 1, 1); // (1, 0) 幅=1, 高さ=1
|
588
|
-
|
589
|
-
addButton(downButton, 1, 1, 1, 1); // (1, 1) 幅=1, 高さ=1
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
560
|
|
597
561
|
}
|
598
562
|
|
@@ -602,13 +566,21 @@
|
|
602
566
|
|
603
567
|
|
604
568
|
|
569
|
+
|
570
|
+
|
571
|
+
public void paintComponent(Graphics A00) {
|
572
|
+
|
605
|
-
|
573
|
+
super.paintComponent(A00);
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
574
|
+
|
575
|
+
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
|
580
|
+
|
611
|
-
|
581
|
+
A00.drawString("縮小(" + C01 + "%)", 0, 10);
|
582
|
+
|
583
|
+
A00.drawImage(I00, 0, 20, I01 * C01 / 100, I02 * C01 / 100, this); //縮小した画像の配置座標
|
612
584
|
|
613
585
|
|
614
586
|
|
@@ -618,92 +590,34 @@
|
|
618
590
|
|
619
591
|
|
620
592
|
|
621
|
-
|
593
|
+
```
|
594
|
+
|
595
|
+
|
596
|
+
|
622
|
-
|
597
|
+
ScreenShot
|
598
|
+
|
599
|
+
```lang-java
|
600
|
+
|
623
|
-
|
601
|
+
public class ScreenShot {
|
624
|
-
|
602
|
+
|
603
|
+
|
604
|
+
|
625
|
-
|
605
|
+
public void screenCapture(File filepath) throws AWTException, IOException {
|
606
|
+
|
626
|
-
|
607
|
+
Robot robot = new Robot();
|
608
|
+
|
627
|
-
|
609
|
+
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
628
|
-
|
610
|
+
|
629
|
-
|
611
|
+
BufferedImage image = robot.createScreenCapture(
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
612
|
+
|
634
|
-
|
635
|
-
|
613
|
+
new Rectangle(0, 0, screenSize.width, screenSize.height));
|
636
|
-
|
637
|
-
|
614
|
+
|
638
|
-
|
639
|
-
if(i>99)i=0;
|
640
|
-
|
641
|
-
|
615
|
+
ImageIO.write(image, "PNG", filepath); //PNGファイルの保存
|
642
|
-
|
643
|
-
|
616
|
+
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
617
|
+
}
|
648
|
-
|
649
|
-
else if(cmd.equals("downButton")){
|
650
|
-
|
651
|
-
int i = Integer.parseInt(itemField.getText());
|
652
|
-
|
653
|
-
i--;
|
654
|
-
|
655
|
-
if(i<0)i=99;
|
656
|
-
|
657
|
-
//itemField.setText(String.format("%1$02d",i)); //0埋め
|
658
|
-
|
659
|
-
itemField.setText(String.valueOf(i));
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
}
|
664
|
-
|
665
|
-
}
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
618
|
|
673
619
|
}
|
674
620
|
|
675
621
|
|
676
622
|
|
677
|
-
|
678
|
-
|
679
623
|
```
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
ScreenShot
|
684
|
-
|
685
|
-
```lang-java
|
686
|
-
|
687
|
-
public class ScreenShot {
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
public void screenCapture(File filepath) throws AWTException, IOException {
|
692
|
-
|
693
|
-
Robot robot = new Robot();
|
694
|
-
|
695
|
-
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
696
|
-
|
697
|
-
BufferedImage image = robot.createScreenCapture(
|
698
|
-
|
699
|
-
new Rectangle(0, 0, screenSize.width, screenSize.height));
|
700
|
-
|
701
|
-
ImageIO.write(image, "PNG", filepath); //PNGファイルの保存
|
702
|
-
|
703
|
-
}
|
704
|
-
|
705
|
-
}
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
```
|
1
ソースコードの修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
[Java Swing]キャプチャ
|
1
|
+
[Java Swing]キャプチャツールでのキャプチャ画像表示
|
test
CHANGED
File without changes
|