📄 pictureplatform.java
字号:
class newActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
mp.setBackground(Color.WHITE);
mp.clear();
}
}
class OpenL implements ActionListener {
private int x = 10;
private int y = 10;
public void actionPerformed(ActionEvent e) {
JFileChooser c = new JFileChooser(new File("."));
c.setFileSelectionMode(JFileChooser.FILES_ONLY);
int rVal = c.showOpenDialog(PicturePlatform.this);
if(rVal == JFileChooser.APPROVE_OPTION)
{
File file = c.getSelectedFile();
String name = file.getName();
for(int i = name.length()-1; i >= 0; i --)
{
if(name.charAt(i) == '.')
{
name = name.substring(i+1);
if(name.equals("jpg") || name.equals("gif")||
name.equals("PNG"))
{
try
{
BufferedImage im = ImageIO.read(file);
mp.getGraphics().drawImage(im,x,y,mp);
BufferedImage cp = ImageIO.read(file);
mp.loadImage(im,cp,x,y);
mp.setFile(file);
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
}
else if(name.equals("roger"))
{
try
{
mp.clear();
ObjectInputStream input = new ObjectInputStream(new FileInputStream(file));
Shape temp = null;
int tempIndex = input.readInt();
for(i = 1; i < tempIndex; i ++)
{
temp = (Shape)input.readObject();
mp.item[i] = temp;
}
mp.index = tempIndex - 1;
mp.repaint();
Color tempColor = (Color)input.readObject();
mp.setBackground(tempColor);
input.close();
}
catch(EOFException endofFileException)
{
JOptionPane.showMessageDialog(null,"no more record in file",
"class not found",JOptionPane.ERROR_MESSAGE );
}
catch(ClassNotFoundException classNotFoundException)
{
JOptionPane.showMessageDialog(null,"Unable to Create Object",
"end of file",JOptionPane.ERROR_MESSAGE );
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
}
else
{
JOptionPane.showMessageDialog(null,"can only open format of ' jpg , gif , PNG , roger '",
"WRONG FILE",JOptionPane.ERROR_MESSAGE);
}
break;
}
}
}
}
}
class SaveL implements ActionListener {
public void actionPerformed(ActionEvent e) {
JFileChooser c = new JFileChooser(new File("."));
c.setFileSelectionMode(JFileChooser.FILES_ONLY);
int rVal = c.showSaveDialog(PicturePlatform.this);
if(rVal == JFileChooser.APPROVE_OPTION)
{
File file = c.getSelectedFile();
file.delete();
String name = file.getName();
for(int i = name.length()-1; i >= 0; i --)
{
if(name.charAt(i) == '.')
{
name = name.substring(i+1);
if(name.equals("jpg") || name.equals("gif")||
name.equals("PNG"))
{
if(mp.getImage() != null)
{
try
{
int wideth = mp.getImage().getWidth(null);
int height = mp.getImage().getHeight(null);
BufferedImage tag = new BufferedImage(wideth,height,BufferedImage.TYPE_4BYTE_ABGR);
//test
/*for(i = 1; i <= mp.index; i ++)
{
if(mp.item[i] instanceof Rect)
{
int x = ((mp.item[i].x1 - mp.item[i].x2) >= 0)?mp.item[i].x2:mp.item[i].x1;
int y = ((mp.item[i].y1 - mp.item[i].y2) >= 0)?mp.item[i].y2:mp.item[i].y1;
tag.getGraphics().drawRect(x,y,Math.abs(mp.item[i].x2-mp.item[i].x1),Math.abs(mp.item[i].y2-mp.item[i].y1));
}
}*/
tag.getGraphics().drawImage(mp.getImage(),0,0,wideth,height,null);
FileOutputStream out=new FileOutputStream(file.getAbsoluteFile());
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(tag);
out.close();
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
}
}
else if(name.equals("roger"))
{
try
{
ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(file));
Shape temp;
output.writeInt(mp.index + 1);
for(i = 1; i <= mp.index; i ++)
{
temp = mp.item[i];
output.writeObject(temp);
output.flush();
}
output.writeObject(mp.getBackground());
output.close();
/*JOptionPane.showMessageDialog(null,file.toString(),
"WRONG FILE",JOptionPane.DEFAULT_OPTION);*/
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
}
else
{
JOptionPane.showMessageDialog(null,"can only save format of ' jpg , gif , PNG , roger '",
"WRONG FILE",JOptionPane.ERROR_MESSAGE);
}
break;
}
}
}
}
}
class catchRedActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
mp.catchRed();
}
}
class catchGreenActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
mp.catchGreen();
}
}
class catchBlueActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
mp.catchBlue();
}
}
class recoverActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
mp.recover();
}
}
class zoomHalfActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
mp.zoomToHalf();
}
}
class zoomDoubleActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
mp.zoomToDouble();
}
}
class cutActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
mp.cut();
}
}
class changeRActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
mp.changeR();
}
}
class changeLActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
mp.changeL();
}
}
class extendXActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
mp.scaleX();
}
}
class extendYActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
mp.scaleY();
}
}
public static void main(String[] args) {
PicturePlatform frame = new PicturePlatform();
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e)
{
throw new RuntimeException(e);
}
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1200,700);
frame.setVisible(true);
frame.setResizable(false);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -