芽可
|
分享:
▼
x0
|
[Java][求助] 请问在jScrollPane的图片另存新档的程式码错误?
|
|
|
|
执行之后会跑出以下错误讯息: open3.java:110: cannot find symbol symbol : class ExampleFileFilter location: class open3 ExampleFileFilter filter = new ExampleFileFilter(); ^ open3.java:110: cannot find symbol symbol : class ExampleFileFilter location: class open3 ExampleFileFilter filter = new ExampleFileFilter(); ^ open3.java:114: cannot find symbol symbol : variable chooser location: class open3 chooser.setFileFilter(filter); ^ open3.java:115: parent is not public in java.awt.Component; cannot be accessed f rom outside package int returnVal = chooser.showOpenDialog(parent); ^ open3.java:115: cannot find symbol symbol : variable chooser location: class open3 int returnVal = chooser.showOpenDialog(parent); ^ open3.java:118: cannot find symbol symbol : variable chooser location: class open3 chooser.getSelectedFile().getName()); ^ open3.java:132: inner classes cannot have static declarations public static void main(String[] args) { ^ 7 errors 如果去掉public void saveImage1()这一段的话,则不会出现错误。 开启档案的方面很正常,但是在新增储存功能的时候找了资料依然改不太出来>"< 储存的部份搞不太懂,拜托帮我看一下问题出在哪QQ (PS:附件是有问题的JAVA档案,因为不能上传.java档,请自行转成java档来执行QQ) import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.awt.image.*; public class open3 extends JFrame implements ActionListener{ private Image m = null; private Image m2 = null; private String dir = null; JPanel contentPane; JScrollPane jScrollPane1 = new JScrollPane(); JScrollPane jScrollPane2 = new JScrollPane(); static FileDialog dialog; //宣告档案对话方块变数 JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); MenuBar menubar1; //宣告功能表列变数 Menu mnuFile; //宣告功能表变数 MenuItem itmOpen1, itmExit, itmSave; //宣告功能项变数 java.awt.Image iconimg1; java.awt.Image iconimg2; //Construct the frame public open3() { enableEvents(AWTEvent.WINDOW_EVENT_MA .. 访客只能看到部份内容,免费 加入会员 或由脸书 Google 可以看到全部内容
[ 此文章被芽可在2008-09-24 18:06重新编辑 ]
|
|
|
|
|
|
芽生可音
|
x0
[楼 主]
From:台湾 | Posted:2008-09-24 10:48 |
|
|
overing
|
分享:
▲
▼
下面是引用芽可于2008-09-24 18:04发表的 :
请问如果不使用ExampleFileFilter这个CLASS的话,这段程式码成立吗? chooser要宣告成什么@@?
.java档不能上传,所以我把程式码放在.txt档里面上传@@ 我想应该副档名过滤的类别要换成 FileNameExtensionFilter 才对(比较好用) http://java.sun.com/javase/6/docs/api/javax/swi...eExtensionFilter.html建构式 FileNameExtensionFilter('说明文','附档名1','附档名2','附档名3',...) EX 复制程式
JFileChooser fileChooser = new JFileChooser();
//个人比较习关用JFileChooser
//不过您使用的FileDialog能不能支援还要查一下@@
fileChooser.addChoosableFileFilter(
new FileNameExtensionFilter("C/C++ source code(*.c *.cc *.cpp *.h)", "c", "cc", "cpp", "h"));
fileChooser.addChoosableFileFilter(
new FileNameExtensionFilter("Java source code(*.java)", "java"));
所以以您的情况来讲 save 那个方法应该改成...试试看 复制程式
public void saveImage1(){
FileDialog dlg = new FileDialog(this, "Choose Image", FileDialog.SAVE);//选择档案
//set current directory
if(dir != null){
dlg.setDirectory(dir);
}
FileNameExtensionFilter filter = new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif");
dlg.setFilenameFilter(filter); //这边之后的chooser应该改成你宣告的FileDialog, 也就是dlg
int returnVal = dlg.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
dlg.getSelectedFile().getName());
}
}
还有就是开发视窗程式最好尽可能统一都用javax.swing底下的类别 比较不用顾虑太多低阶的问题...也比较美观点 不过相对的效能会稍稍的...降低些 补充一下~show那边的parent您也没宣告 通常这种对话框会以前一层的容器为父 所以parent建议可以改成this 指向open3的实体 刚刚又发现...FileDialog是没有showOpenDialog这个方法的... 整篇下来问题蛮多的...于事就帮你值街都换成JFileChooser 复制程式
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.File;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
public class open3 extends JFrame implements ActionListener{
private Image m = null;
private Image m2 = null;
private File dir = null; //*
JPanel contentPane;
JScrollPane jScrollPane1 = new JScrollPane();
JScrollPane jScrollPane2 = new JScrollPane();
//static FileDialog dialog; //宣告档案对话方块变数
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
MenuBar menubar1; //宣告功能表列变数
Menu mnuFile; //宣告功能表变数
MenuItem itmOpen1, itmExit, itmSave; //宣告功能项变数
java.awt.Image iconimg1;
java.awt.Image iconimg2;
//Construct the frame
public open3() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(null);
this.setSize(new Dimension(700, 500)); //JFrame大小
this.setTitle("open");
jScrollPane1.setBounds(new Rectangle(30, 30, 300, 240)); //内框位置+大小
contentPane.add(jScrollPane1, null);
jScrollPane1.getViewport().add(jLabel1, null);
jScrollPane2.setBounds(new Rectangle(350, 30, 300, 240)); //内框位置+大小
contentPane.add(jScrollPane2, null);
jScrollPane2.getViewport().add(jLabel2, null);
menubar1 = new MenuBar(); //建立功能表列
mnuFile = new Menu("File"); //建立档案功能表
menubar1.add(mnuFile); //加入档案功能表
itmOpen1 = new MenuItem("开启档案"); //建立开启旧档功能项
itmSave = new MenuItem("Save"); //建立储存档案功能项
itmExit = new MenuItem("EXIT"); //建立结束功能项
mnuFile.add(itmOpen1); //加入开启旧档到档案功能表
mnuFile.add(itmSave); //加入存档到档案功能表
mnuFile.add(itmExit); //加入结束到档案功能表
//dialog = new FileDialog(this, "开启旧档"); //建立对话方块
itmOpen1.addActionListener(this);
//dialog = new FileDialog(this, "另存新档"); //建立对话方块
itmSave.addActionListener(this);
itmExit.addActionListener(this);//加入结束功能项动作监听
setMenuBar(menubar1); //设定视窗功能表列
}
//-----------------------------------------
public void actionPerformed(ActionEvent e) { //执行视窗Action事件方法
if(e.getSource() == itmOpen1){
//dialog.setVisible(true);//显示对话方块
loadImage1();
}
else if(e.getSource() == itmSave){
//dialog.setVisible(true);//显示对话方块
saveImage1();
}
else if(e.getSource() == itmExit) { //若为结束功能项事件
System.exit(0); //结束并关闭视窗
}
}
public void loadImage1(){
JFileChooser jfc = new JFileChooser();//选择档案
jfc.setDialogTitle("Choose Image");
//set current directory
if(dir != null){
jfc.setCurrentDirectory(dir);
}
FileNameExtensionFilter filter =
new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif");
jfc.addChoosableFileFilter(filter);
int returnVal = jfc.showOpenDialog(this);
//get image name and path
if(returnVal == JFileChooser.APPROVE_OPTION) {
String imgFile = jfc.getSelectedFile().getName();
dir = jfc.getCurrentDirectory();
//create image using filename
Toolkit tk = Toolkit.getDefaultToolkit();
m = tk.getImage(imgFile);
ImageIcon tempIcon1 = new ImageIcon(m);
iconimg1=tempIcon1.getImage();
jLabel1.setIcon(tempIcon1);
m2 = tk.getImage(imgFile);
ImageIcon tempIcon2 = new ImageIcon(m2);
iconimg2 = tempIcon2.getImage();
jLabel2.setIcon(tempIcon2);
}
}
public void saveImage1(){
JFileChooser jfc = new JFileChooser();//选择档案
jfc.setDialogTitle("Choose Image");
//set current directory
if(dir != null){
jfc.setCurrentDirectory(dir);
}
FileNameExtensionFilter filter =
new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif");
jfc.addChoosableFileFilter(filter);
int returnVal = jfc.showSaveDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
jfc.getSelectedFile().getName());
}
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
open3 _frame = new open3();
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
_frame.validate();
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = _frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
_frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
_frame.setVisible(true);
}
catch(Exception e) {
e.printStackTrace();
}
}
}
[ 此文章被overing在2008-09-24 21:21重新编辑 ]
|
Zippy G2 600W Intel C2Q Q9550 Gigabyte GA-X48-DQ6 Gigabyte GV-NX96T512H-B G-skill pi 1100MHz 2Gx4 ACARD ANS-9010 32GB (Windows7 10sec boot!!) WD 150GB(WD1500ADFD)/640GB(6400AASK)
|
x0
[3 楼]
From:未知地址 | Posted:2008-09-24 20:21 |
|
|
overing
|
分享:
▲
▼
复制程式
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.File;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
public class Open3 extends JFrame implements ActionListener{
private Image m = null;
private Image m2 = null;
private File dir = null; //*
JPanel contentPane;
JScrollPane jScrollPane1 = new JScrollPane();
JScrollPane jScrollPane2 = new JScrollPane();
//static FileDialog dialog; //宣告档案对话方块变数
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
MenuBar menubar1; //宣告功能表列变数
Menu mnuFile; //宣告功能表变数
MenuItem itmOpen1, itmExit, itmSave; //宣告功能项变数
java.awt.Image iconimg1;
java.awt.Image iconimg2;
//Construct the frame
public Open3() {
jbInit();
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//Component initialization
private void jbInit() {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(null);
this.setSize(new Dimension(700, 500)); //JFrame大小
this.setTitle("image view");
jScrollPane1.setBounds(new Rectangle(30, 30, 300, 240)); //内框位置+大小
contentPane.add(jScrollPane1, null);
jScrollPane1.getViewport().add(jLabel1, null);
jScrollPane2.setBounds(new Rectangle(350, 30, 300, 240)); //内框位置+大小
contentPane.add(jScrollPane2, null);
jScrollPane2.getViewport().add(jLabel2, null);
menubar1 = new MenuBar(); //建立功能表列
mnuFile = new Menu("档案"); //建立档案功能表
menubar1.add(mnuFile); //加入档案功能表
itmOpen1 = new MenuItem("开启档案"); //建立开启旧档功能项
itmSave = new MenuItem("储存档案"); //建立储存档案功能项
itmExit = new MenuItem("结束"); //建立结束功能项
mnuFile.add(itmOpen1); //加入开启旧档到档案功能表
mnuFile.add(itmSave); //加入存档到档案功能表
mnuFile.add(itmExit); //加入结束到档案功能表
itmOpen1.addActionListener(this);
itmSave.addActionListener(this);
itmExit.addActionListener(this);//加入结束功能项动作监听
setMenuBar(menubar1); //设定视窗功能表列
}
public void actionPerformed(ActionEvent e) { //执行视窗Action事件方法
if(e.getSource() == itmOpen1){
loadImage1();
}
else if(e.getSource() == itmSave){
saveImage1();
}
else if(e.getSource() == itmExit) { //若为结束功能项事件
System.exit(0); //结束并关闭视窗
}
}
public void loadImage1(){
JFileChooser jfc = new JFileChooser();//选择档案
jfc.setDialogTitle("Choose Image");
//set current directory
if(dir != null){
jfc.setCurrentDirectory(dir);
}
FileNameExtensionFilter filter =
new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif");
jfc.addChoosableFileFilter(filter);
int returnVal = jfc.showOpenDialog(this);
//get image name and path
if(returnVal == JFileChooser.APPROVE_OPTION) {
String imgFile = jfc.getCurrentDirectory() + "\\" + jfc.getSelectedFile().getName();
dir = jfc.getCurrentDirectory();
//create image using filename
Toolkit tk = Toolkit.getDefaultToolkit();
m = tk.getImage(imgFile);
ImageIcon tempIcon1 = new ImageIcon(imgFile);
iconimg1=tempIcon1.getImage();
jLabel1.setIcon(tempIcon1);
m2 = tk.getImage(imgFile);
ImageIcon tempIcon2 = new ImageIcon(imgFile);
iconimg2 = tempIcon2.getImage();
jLabel2.setIcon(tempIcon2);
jLabel1.updateUI();
jLabel2.updateUI();
}
}
public void saveImage1(){
JFileChooser jfc = new JFileChooser();//选择档案
jfc.setDialogTitle("Choose Image");
//set current directory
if(dir != null){
jfc.setCurrentDirectory(dir);
}
FileNameExtensionFilter filter =
new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif");
jfc.addChoosableFileFilter(filter);
int returnVal = jfc.showSaveDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
jfc.getSelectedFile().getName());
}
}
public static void main(String[] args) {
new Open3().setVisible(true);
}
}
|
Zippy G2 600W Intel C2Q Q9550 Gigabyte GA-X48-DQ6 Gigabyte GV-NX96T512H-B G-skill pi 1100MHz 2Gx4 ACARD ANS-9010 32GB (Windows7 10sec boot!!) WD 150GB(WD1500ADFD)/640GB(6400AASK)
|
x0
[4 楼]
From:未知地址 | Posted:2008-09-24 21:54 |
|
|
overing
|
分享:
▲
▼
初步搞定版... Java的内建套件真的是非常的齐全 不过因为你只有用JAP跟GIF两种格式 所以有些判断试写得很糟糕 你先看看~有空再上注解 复制程式
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import javax.imageio.*;
import javax.imageio.stream.ImageOutputStream;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
public class Open3 extends JFrame implements ActionListener{
private BufferedImage m = null; //编辑中的缓冲影像(原始图样用做对照)
private BufferedImage m2 = null; //编辑中的缓冲影像(未来可能为套用过效果的)
private File dir = null; //以开启的档案路径
JPanel contentPane;
JScrollPane jScrollPane1 = new JScrollPane();
JScrollPane jScrollPane2 = new JScrollPane();
//static FileDialog dialog; //宣告档案对话方块变数
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
MenuBar menubar1; //宣告功能表列变数
Menu mnuFile; //宣告功能表变数
MenuItem itmOpen1, itmExit, itmSave; //宣告功能项变数
//Construct the frame
public Open3() {
jbInit();
this.setLocationRelativeTo(null); //视窗置中
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //如果点[X]就视同关闭程式
}
//Component initialization
private void jbInit() {
contentPane = (JPanel) this.getContentPane(); //取得Fram的内容层
contentPane.setLayout(null); //设定布局为NULL
this.setSize(new Dimension(700, 500)); //JFrame大小
this.setTitle("image view"); //视窗标题
jScrollPane1.setBounds(new Rectangle(30, 30, 300, 240)); //内框位置+大小
contentPane.add(jScrollPane1, null);
jScrollPane1.getViewport().add(jLabel1, null);
jScrollPane2.setBounds(new Rectangle(350, 30, 300, 240)); //内框位置+大小
contentPane.add(jScrollPane2, null);
jScrollPane2.getViewport().add(jLabel2, null);
menubar1 = new MenuBar(); //建立功能表列
mnuFile = new Menu("档案"); //建立档案功能表
menubar1.add(mnuFile); //加入档案功能表
itmOpen1 = new MenuItem("开启档案"); //建立开启旧档功能项
itmSave = new MenuItem("储存档案"); //建立储存档案功能项
itmExit = new MenuItem("结束"); //建立结束功能项
mnuFile.add(itmOpen1); //加入开启旧档到档案功能表
mnuFile.add(itmSave); //加入存档到档案功能表
mnuFile.add(itmExit); //加入结束到档案功能表
itmOpen1.addActionListener(this);
itmSave.addActionListener(this);
itmExit.addActionListener(this);//加入结束功能项动作监听
setMenuBar(menubar1); //设定视窗功能表列
}
public void actionPerformed(ActionEvent e) { //执行视窗Action事件方法
if(e.getSource() == itmOpen1){
loadImage1();
}
else if(e.getSource() == itmSave){
saveImage1();
}
else if(e.getSource() == itmExit) { //若为结束功能项事件
System.exit(0); //结束并关闭视窗
}
}
public void loadImage1(){
JFileChooser jfc = new JFileChooser(); //档案选择对话框
jfc.setDialogTitle("开启档案"); //设定对话框标题
if(dir != null){
jfc.setCurrentDirectory(dir); //如果有路径记录就从路径位置
}
jfc.addChoosableFileFilter(new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif")); //加入档名过虑器
int returnVal = jfc.showOpenDialog(this); //传回值
//get image name and path
if(returnVal == JFileChooser.APPROVE_OPTION) { //如果对话视窗是按了[OK]或[确定]之类的按钮结束
try {
String imgFile = jfc.getCurrentDirectory() + "\\" + jfc.getSelectedFile().getName(); //档案完整路径
dir = jfc.getCurrentDirectory(); //储存路径记录
this.m = ImageIO.read(jfc.getSelectedFile()); //读入影像
ImageIcon tempIcon1 = new ImageIcon(imgFile);
jLabel1.setIcon(tempIcon1);
this.m2 = ImageIO.read(jfc.getSelectedFile()); //读入影像
ImageIcon tempIcon2 = new ImageIcon(imgFile);
jLabel2.setIcon(tempIcon2);
jLabel1.updateUI(); //更新画面
jLabel2.updateUI(); //更新画面
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
public void saveImage1(){
JFileChooser jfc = new JFileChooser(); //选择档案
jfc.setDialogTitle("储存档案"); //设定对话框标题
//set current directory
if(dir != null){
jfc.setCurrentDirectory(dir); //储存路径记录
}
//存档的时候要讲名是那种档案
jfc.addChoosableFileFilter(new FileNameExtensionFilter("jpeg file", "jpg")); //加入档名过虑器
jfc.addChoosableFileFilter(new FileNameExtensionFilter("gif file", "gif")); //加入档名过滤器
int returnVal = jfc.showSaveDialog(this); //储存传回值
if(returnVal == JFileChooser.APPROVE_OPTION) { //如果对话视窗是按了[OK]或[确定]之类的按钮结束
String fileType = jfc.getFileFilter().getDescription(); //档案类型
fileType = (fileType.equals("jpeg file") ? fileType = "jpg" : "gif"); //转成3字元附档名
Iterator writers = ImageIO.getImageWritersBySuffix(fileType); //依据档案类型取得图形写入器
ImageWriter writer = (ImageWriter) writers.next();
String fullFileName = jfc.getCurrentDirectory() + "\\" + jfc.getSelectedFile().getName(); //完整档名
if(!fullFileName.endsWith(fileType)) fullFileName = fullFileName + "." + fileType; //如果使用者没有键入付档名则自动补上
File f = new File(fullFileName); //包装成档案物件
try {
ImageOutputStream ios = ImageIO.createImageOutputStream(f); //建立图形输出串流
writer.setOutput(ios); //设定图形输出串流
writer.write(this.m2); //将图形写入
ios.close(); //关闭档案串流
//System.out.println("You chose to open this file: " + jfc.getSelectedFile().getName());
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
public static void main(String[] args) {
new Open3().setVisible(true);
}
}
[ 此文章被overing在2008-09-25 12:29重新编辑 ]
|
Zippy G2 600W Intel C2Q Q9550 Gigabyte GA-X48-DQ6 Gigabyte GV-NX96T512H-B G-skill pi 1100MHz 2Gx4 ACARD ANS-9010 32GB (Windows7 10sec boot!!) WD 150GB(WD1500ADFD)/640GB(6400AASK)
|
x0
[7 楼]
From:未知地址 | Posted:2008-09-25 01:28 |
|
|
overing
|
分享:
▲
下面是引用芽可于2008-09-25 20:16发表的 : 真的可以了QQ 呜呜,我该怎么感谢你QQ? 报答就不用了... 继续玩吧!~XD 下面这个自己加了一些新功能~ 用NetBeans来设计GUI会比较方便喔!~ 像38~235行就都是NetBeans帮忙建立的(自己不用打) (一些英文注解是NettBeans加的~可以拿掉无访) 玩玩看 复制程式
/*
* MainJFrame.java
*
* Created on 2008年9月25日, 下午 4:57
*/
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
/**
*
* @author Overing Zero
*/
public class MainJFrame extends JFrame implements AdjustmentListener {
private BufferedImage originImage = null; //编辑中的缓冲影像(原始图样用做对照)
private BufferedImage m2 = null; //编辑中的缓冲影像(未来可能为套用过效果的)
private File dir = null; //以开启的档案路径
/** Creates new form MainJFrame */
public MainJFrame() {
initComponents();
this.setLocationRelativeTo(null); //视窗置中
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
jLabel3 = new javax.swing.JLabel();
before_JScrollPane = new javax.swing.JScrollPane();
beforeImage_JLabel = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
after_JScrollPane = new javax.swing.JScrollPane();
afterImage_JLabel = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
addBlack_JButton = new javax.swing.JButton();
addW_JButton = new javax.swing.JButton();
addRed_JButton = new javax.swing.JButton();
addGreen_JButton = new javax.swing.JButton();
addBlue_JButton = new javax.swing.JButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
save_JMenuItem = new javax.swing.JMenuItem();
load_JMenuItem = new javax.swing.JMenuItem();
jSeparator1 = new javax.swing.JSeparator();
exit_JMenuItem = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jSeparator2 = new javax.swing.JSeparator();
jMenu4 = new javax.swing.JMenu();
jMenu3 = new javax.swing.JMenu();
about_JMenuItem = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Image Editer");
setMinimumSize(new java.awt.Dimension(400, 300));
getContentPane().setLayout(new java.awt.GridBagLayout());
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel3.setText("Before");
jLabel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
getContentPane().add(jLabel3, gridBagConstraints);
before_JScrollPane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener(){
public void adjustmentValueChanged(AdjustmentEvent e) {
MainJFrame.this.after_JScrollPane.getHorizontalScrollBar().setValue(e.getValue());
}
});
before_JScrollPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener(){
public void adjustmentValueChanged(AdjustmentEvent e) {
MainJFrame.this.after_JScrollPane.getVerticalScrollBar().setValue(e.getValue());
}
});
before_JScrollPane.setViewportView(beforeImage_JLabel);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridheight = java.awt.GridBagConstraints.RELATIVE;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
getContentPane().add(before_JScrollPane, gridBagConstraints);
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel4.setText("After");
jLabel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
getContentPane().add(jLabel4, gridBagConstraints);
after_JScrollPane.getHorizontalScrollBar().addAdjustmentListener(this);
after_JScrollPane.getVerticalScrollBar().addAdjustmentListener(this);
after_JScrollPane.setViewportView(afterImage_JLabel);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridheight = java.awt.GridBagConstraints.RELATIVE;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
getContentPane().add(after_JScrollPane, gridBagConstraints);
jPanel1.setLayout(new java.awt.GridLayout(1, 5, 2, 2));
addBlack_JButton.setText("黑");
addBlack_JButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
addBlack_JButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
toolButtonsActionPerformed(evt);
}
});
jPanel1.add(addBlack_JButton);
addW_JButton.setText("白");
addW_JButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
toolButtonsActionPerformed(evt);
}
});
jPanel1.add(addW_JButton);
addRed_JButton.setText("红");
addRed_JButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
toolButtonsActionPerformed(evt);
}
});
jPanel1.add(addRed_JButton);
addGreen_JButton.setText("绿");
addGreen_JButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
toolButtonsActionPerformed(evt);
}
});
jPanel1.add(addGreen_JButton);
addBlue_JButton.setText("蓝");
addBlue_JButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
toolButtonsActionPerformed(evt);
}
});
jPanel1.add(addBlue_JButton);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
getContentPane().add(jPanel1, gridBagConstraints);
jMenu1.setText("档案");
save_JMenuItem.setText("开启档案");
save_JMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
open_JMenuItemActionPerformed(evt);
}
});
jMenu1.add(save_JMenuItem);
load_JMenuItem.setText("储存档案");
load_JMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
save_JMenuItemActionPerformed(evt);
}
});
jMenu1.add(load_JMenuItem);
jMenu1.add(jSeparator1);
exit_JMenuItem.setText("离开");
exit_JMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exit_JMenuItemActionPerformed(evt);
}
});
jMenu1.add(exit_JMenuItem);
jMenuBar1.add(jMenu1);
jMenu2.setText("编辑");
jMenuItem1.setText("Undo");
jMenu2.add(jMenuItem1);
jMenuItem2.setText("Redo");
jMenu2.add(jMenuItem2);
jMenu2.add(jSeparator2);
jMenu4.setText("ActionLog");
jMenu2.add(jMenu4);
jMenuBar1.add(jMenu2);
jMenu3.setText("关于");
about_JMenuItem.setText("关于本程式");
about_JMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
about_JMenuItemActionPerformed(evt);
}
});
jMenu3.add(about_JMenuItem);
jMenuBar1.add(jMenu3);
setJMenuBar(jMenuBar1);
pack();
}// </editor-fold>
private void open_JMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser jfc = new JFileChooser(); //档案选择对话框
jfc.setDialogTitle("开启档案"); //设定对话框标题
if(dir != null) jfc.setCurrentDirectory(dir); //如果有路径记录就从路径位置
jfc.addChoosableFileFilter(new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif")); //加入档名过虑器
int returnVal = jfc.showOpenDialog(this); //传回值
//get image name and path
if(returnVal == JFileChooser.APPROVE_OPTION) { //如果对话视窗是按了[OK]或[确定]之类的按钮结束
try {
String imgFile = jfc.getCurrentDirectory() + "\\" + jfc.getSelectedFile().getName(); //档案完整路径
dir = jfc.getCurrentDirectory(); //储存路径记录
this.originImage = ImageIO.read(jfc.getSelectedFile()); //读入影像
ImageIcon tempIcon1 = new ImageIcon(this.originImage);
this.beforeImage_JLabel.setIcon(tempIcon1);
this.m2 = ImageIO.read(jfc.getSelectedFile()); //读入影像
ImageIcon tempIcon2 = new ImageIcon(this.m2);
this.afterImage_JLabel.setIcon(tempIcon2);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
private void save_JMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser jfc = new JFileChooser(); //选择档案
jfc.setDialogTitle("储存档案"); //设定对话框标题
if(dir != null) jfc.setCurrentDirectory(dir); //如果有路径记录就从路径位置
//存档的时候要讲明那种档案
jfc.addChoosableFileFilter(new FileNameExtensionFilter("jpeg file", "jpg")); //加入档名过虑器
jfc.addChoosableFileFilter(new FileNameExtensionFilter("gif file", "gif")); //加入档名过滤器
int returnVal = jfc.showSaveDialog(this); //储存传回值
if(returnVal == JFileChooser.APPROVE_OPTION) { //如果对话视窗是按了[OK]或[确定]之类的按钮结束
String fileType = jfc.getFileFilter().getDescription(); //档案类型
fileType = (fileType.equals("jpeg file") ? fileType = "jpg" : "gif"); //转成3字元附档名
String fullFileName = jfc.getCurrentDirectory() + "\\" + jfc.getSelectedFile().getName(); //完整档名
if(!fullFileName.endsWith(fileType)) fullFileName = fullFileName + "." + fileType; //如果使用者没有键入付档名则自动补上
File f = new File(fullFileName); //包装成档案物件
try {
ImageIO.write(m2, fileType, f);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
private void exit_JMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
public void adjustmentValueChanged(AdjustmentEvent e) {
if(e.getSource() == this.before_JScrollPane.getHorizontalScrollBar())
this.after_JScrollPane.getHorizontalScrollBar().setValue(
this.before_JScrollPane.getHorizontalScrollBar().getValue());
if(e.getSource() == this.before_JScrollPane.getVerticalScrollBar())
this.after_JScrollPane.getVerticalScrollBar().setValue(
this.before_JScrollPane.getVerticalScrollBar().getValue());
}
private void toolButtonsActionPerformed(java.awt.event.ActionEvent evt) {
if(m2 == null) return;
Graphics g = this.m2.getGraphics();
if(evt.getSource() == this.addBlack_JButton)
g.setColor(new Color(0, 0, 0, 16));
if(evt.getSource() == this.addW_JButton)
g.setColor(new Color(255, 255, 255, 16));
if(evt.getSource() == this.addRed_JButton)
g.setColor(new Color(255, 0, 0, 16));
if(evt.getSource() == this.addGreen_JButton)
g.setColor(new Color(0, 255, 0, 16));
if(evt.getSource() == this.addBlue_JButton)
g.setColor(new Color(0, 0, 255, 16));
g.fillRect(0, 0,m2.getWidth(), m2.getHeight());
afterImage_JLabel.setIcon(new ImageIcon(this.m2));
}
private void about_JMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
String msg = "名称: Image Editer\n" +
"版本: 0.9" +
"作者: Overing\n" +
"时间: 08/09/24~08/09/25\n" +
"臭虫回报:\n" +
" zero_overing@yahoo.com.tw\n" +
" zero_overing@hotmail.com";
JOptionPane.showMessageDialog(this, msg, "关于本程式", JOptionPane.INFORMATION_MESSAGE);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JMenuItem about_JMenuItem;
private javax.swing.JButton addBlack_JButton;
private javax.swing.JButton addBlue_JButton;
private javax.swing.JButton addGreen_JButton;
private javax.swing.JButton addRed_JButton;
private javax.swing.JButton addW_JButton;
private javax.swing.JLabel afterImage_JLabel;
private javax.swing.JScrollPane after_JScrollPane;
private javax.swing.JLabel beforeImage_JLabel;
private javax.swing.JScrollPane before_JScrollPane;
private javax.swing.JMenuItem exit_JMenuItem;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JPanel jPanel1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
private javax.swing.JMenuItem load_JMenuItem;
private javax.swing.JMenuItem save_JMenuItem;
// End of variables declaration
}
[ 此文章被overing在2008-09-25 22:16重新编辑 ]
此文章被评分,最近评分记录财富:100 (by 三仙) | 理由: ^^ 因为您的参与,让程式设计更容易!! | |
|
|
|
Zippy G2 600W Intel C2Q Q9550 Gigabyte GA-X48-DQ6 Gigabyte GV-NX96T512H-B G-skill pi 1100MHz 2Gx4 ACARD ANS-9010 32GB (Windows7 10sec boot!!) WD 150GB(WD1500ADFD)/640GB(6400AASK)
|
x1
[9 楼]
From:未知地址 | Posted:2008-09-25 21:27 |
|
|
|