📄 painter.java
字号:
if(!changed)
return;
File file = modelFile;
if(file == null) {
file = showDialog("Save Picture",
"Save",
"Save the Picture",
's',
new File(files.getCurrentDirectory(), savefilename));
System.out.println("\nunknown");
if(file == null || (file.exists() && // Check for existence
JOptionPane.NO_OPTION == // Overwrite warning
JOptionPane.showConfirmDialog(painter.this,
file.getName()+" exists. Overwrite?",
"Confirm Save As",
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE)))
return; // No selected file
}
savePicture(file);
}
// Display a custom file save dialog
private File showDialog(String dialogTitle,
String approveButtonText,
String approveButtonTooltip,
char approveButtonMnemonic,
File file) { // Current file - if any
files.setDialogTitle(dialogTitle);
files.setApproveButtonText(approveButtonText);
files.setApproveButtonToolTipText(approveButtonTooltip);
files.setApproveButtonMnemonic(approveButtonMnemonic);
files.setFileSelectionMode(files.FILES_ONLY);
files.rescanCurrentDirectory();
files.setSelectedFile(file);
int result = files.showDialog(painter.this, null); // Show the dialog
return (result == files.APPROVE_OPTION) ? files.getSelectedFile() : null;
}
private void savePicture(File outFile) {
try {
FileOutputStream out=new FileOutputStream(outFile);
//oukt.writeObject(getImage());
out.close(); // Flush & close it
} catch(IOException e) {
System.err.println(e);
/*JOptionPane.showMessageDialog(SketchFrame.this,
"Error writing a sketch file.",
"File Output Error",
JOptionPane.ERROR_MESSAGE);*/
return; // Serious error - return
}
if(outFile != modelFile) { // If we are saving to a new file
// we must update the window
modelFile = outFile; // Save file reference
filename = modelFile.getName(); // Update the file name
setTitle(frameTitle + modelFile.getPath()); // Change the window
// title
}
changed = false; // Set as unchanged
}
class RWindow extends JDialog{
public RWindow(JFrame frame){
super(frame, "rotate", true);
Container cp = getContentPane();
ButtonGroup g = new ButtonGroup();
JRadioButton
flow = new JRadioButton("flow turn", false),
vertical = new JRadioButton("vertical turn", false),
choose = new JRadioButton("choose an angle turn ", false);
g.add(flow);
g.add(vertical);
g.add(choose);
ButtonGroup angle = new ButtonGroup();
A90= new JRadioButton("90 degree ", false);
A180 = new JRadioButton("180 degree ", false);
A270 = new JRadioButton("270 degree ", false);
angle.add(A90);
angle.add(A180);
angle.add(A270);
cp.setLayout(new FlowLayout(FlowLayout.LEADING));
cp.add(flow);
cp.add(vertical);
cp.add(choose);
cp.add(A90);
cp.add(A180);
cp.add(A270);
A90.setEnabled(false);
A180.setEnabled(false);
A270.setEnabled(false);
ok=new JButton("OK");
cancel=new JButton("Cancel");
cp.add(ok);
cp.add(cancel);
setSize(180,300);
flow.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
A90.setEnabled(false);
A180.setEnabled(false);
A270.setEnabled(false);
}
});
vertical.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
A90.setEnabled(false);
A180.setEnabled(false);
A270.setEnabled(false);
}
});
choose.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
A90.setEnabled(true);
A180.setEnabled(true);
A270.setEnabled(true);
}
});
A90.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setAngle(Math.PI/2);
}
});
A180.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setAngle(Math.PI);
}
});
A270.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setAngle(Math.PI*1.5);
}
});
ok.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Transformed tran=new Transformed(getImage(),getAngle(),1);
/*WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
};
//Frame f = new Frame("Transformed");
transformW.dispose();
transformW.addWindowListener(l);
transformW.add(Transformed);
transformW.pack();
//transformW.setSize(new Dimension(600, 300));
transformW.show();
setVisible(false);*/
transform = new Frame("Transformed");
WindowListener la = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
//System.exit(0);
if(e.getID()==WindowEvent.WINDOW_CLOSING){
dispose();
transform.setVisible(false);
}
}
};
transform.addWindowListener(la);
transform.add("Center",tran);
transform.pack();
transform.setSize(new Dimension(1500,1000));
transform.show();
Graphics imageabc=transform.getGraphics();
if(imageabc==null) System.out.println("\nabc");
//label.setIcon(null);
/*Image imageabc=tran.gettheImage();
label.setIcon(new ImageIcon(imageabc));*/
setVisible(false);
changed=true;
}
});
cancel.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setVisible(false);
}
});
}
}
class SWindow extends JDialog{
public SWindow(JFrame frame){
super(frame,"resize",true);
Container cp=getContentPane();
JLabel f=new JLabel("flow: ");
JLabel v=new JLabel("vertical: ");
fl=new JTextField(6);
vtc=new JTextField(6);
JLabel p=new JLabel(" % ");
JLabel p1=new JLabel(" % ");
Sok=new JButton("OK");
Scancel=new JButton("Cancel");
cp.setLayout(new FlowLayout(FlowLayout.CENTER));
Scancel.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setVisible(false);
}
});
cp.add(f);
cp.add(fl);
cp.add(p);
cp.add(v);
cp.add(vtc);
cp.add(p1);
cp.add(Sok);
cp.add(Scancel);
setSize(210,150);
Sok.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//transformW.add("Center",null);
setsizeX(Double.parseDouble(fl.getText())/100);
setsizeY(Double.parseDouble(vtc.getText())/100);
Transformed tranSize=new Transformed(getImage(),getsizeX(),getsizeY(),0);
transformW = new Frame("Transformed");
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
if(e.getID()==WindowEvent.WINDOW_CLOSING){
transformW.setVisible(false);
}
}
};
//Frame fra = new Frame("Transformed");
transformW.addWindowListener(l);
transformW.add("Center", tranSize);
transformW.pack();
transformW.setSize(new Dimension(1500,1000));
transformW.show();
setVisible(false);
changed=true;
}
});
}
}
class HTWindow extends JDialog{
public HTWindow(JFrame frame){
super(frame,"team information",true);
Container cp=getContentPane();
JButton ok=new JButton("OK");
JTextArea text=new JTextArea("Sunjingwan 03080203"+"\nChukongna 03080207"+"\nGenglu 03080214",3,3);
cp.setLayout(new FlowLayout(FlowLayout.CENTER));
cp.add(text);
cp.add(ok);
ok.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setVisible(false);
}
});
setSize(150,150);
}
}
public void setAngle(Double dou){
angle=dou;
}
public Double getAngle(){
return angle;
}
public void setImage(Image ima){
image=ima;
}
public Image getImage(){
return image;
}
public void setsizeX(Double thex){
sizex=thex;
}
public Double getsizeX(){
return sizex;
}
public void setsizeY(Double they){
sizey=they;
}
public Double getsizeY(){
return sizey;
}
public static void main(String[] args){
painter paint=new painter();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -