update
This commit is contained in:
parent
22336b0ada
commit
a83aa09c6b
|
|
@ -81,7 +81,7 @@ public class ColorChoose extends javax.swing.JDialog {
|
|||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
|
||||
this.setVisible(false);
|
||||
this.dispose();
|
||||
}//GEN-LAST:event_jButton1ActionPerformed
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
</Properties>
|
||||
|
|
@ -23,29 +23,25 @@
|
|||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="jPanel1" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="paint" alignment="1" max="32767" attributes="0"/>
|
||||
<Component id="jPanel1" max="32767" attributes="0"/>
|
||||
<Component id="jToolBar1" alignment="0" pref="800" max="32767" attributes="0"/>
|
||||
<Component id="pan" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="jPanel1" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jPanel1" min="-2" pref="27" max="-2" attributes="0"/>
|
||||
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
|
||||
<Component id="paint" pref="335" max="32767" attributes="0"/>
|
||||
<Component id="jToolBar1" min="-2" pref="25" max="-2" attributes="0"/>
|
||||
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
|
||||
<Component id="pan" pref="452" max="32767" attributes="0"/>
|
||||
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="paint.PaintPanel" name="paint">
|
||||
<Properties>
|
||||
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
|
||||
<Color blue="ff" green="ff" red="ff" type="rgb"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Container class="javax.swing.JPanel" name="jPanel1">
|
||||
<Properties>
|
||||
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
|
||||
|
|
@ -59,38 +55,15 @@
|
|||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jButton5" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jButton6" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jButton7" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jButton8" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jButton9" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="181" max="32767" attributes="0"/>
|
||||
<Component id="jToggleButton1" min="-2" pref="89" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jButton10" min="-2" pref="33" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jButton5" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jButton6" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jButton7" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jButton8" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jButton9" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jButton10" alignment="3" min="-2" pref="33" max="-2" attributes="0"/>
|
||||
<Component id="jToggleButton1" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
|
|
@ -104,6 +77,47 @@
|
|||
<Property name="text" type="java.lang.String" value="Paint"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Container class="javax.swing.JToolBar" name="jToolBar1">
|
||||
<Properties>
|
||||
<Property name="rollover" type="boolean" value="true"/>
|
||||
</Properties>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JButton" name="jButton17">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="new"/>
|
||||
<Property name="focusable" type="boolean" value="false"/>
|
||||
<Property name="horizontalTextPosition" type="int" value="0"/>
|
||||
<Property name="verticalTextPosition" type="int" value="3"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton17ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton12">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="save"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton12ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton16">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="open"/>
|
||||
<Property name="focusable" type="boolean" value="false"/>
|
||||
<Property name="horizontalTextPosition" type="int" value="0"/>
|
||||
<Property name="verticalTextPosition" type="int" value="3"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton16ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JToolBar$Separator" name="jSeparator1">
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton5">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="pencil"/>
|
||||
|
|
@ -122,7 +136,7 @@
|
|||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton7">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="rectangle"/>
|
||||
<Property name="text" type="java.lang.String" value="rect"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton7ActionPerformed"/>
|
||||
|
|
@ -144,24 +158,122 @@
|
|||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton9ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton10">
|
||||
<Component class="javax.swing.JToolBar$Separator" name="jSeparator2">
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton13">
|
||||
<Properties>
|
||||
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
|
||||
<Color blue="0" green="0" red="0" type="rgb"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="undo"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton10ActionPerformed"/>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton13ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton14">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="redo"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton14ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JToolBar$Separator" name="jSeparator3">
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="1"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton2">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="2"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton3">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="3"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton3ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton4">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="4"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton4ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton11">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="5"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton11ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JToolBar$Separator" name="jSeparator4">
|
||||
</Component>
|
||||
<Component class="javax.swing.JToggleButton" name="jToggleButton1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="filled"/>
|
||||
<Property name="text" type="java.lang.String" value="fill"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jToggleButton1ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton10">
|
||||
<Properties>
|
||||
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
|
||||
<Color blue="0" green="0" red="0" type="rgb"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="F"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton10ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton15">
|
||||
<Properties>
|
||||
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
|
||||
<Color blue="ff" green="ff" red="ff" type="rgb"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="B"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton15ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Container class="javax.swing.JPanel" name="pan">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
||||
<SubComponents>
|
||||
<Container class="javax.swing.JScrollPane" name="scroll">
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
|
||||
<BorderConstraints direction="Center"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="paint.PaintPanel" name="paint">
|
||||
<Properties>
|
||||
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
|
||||
<Color blue="ff" green="ff" red="ff" type="rgb"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
|
|
|
|||
|
|
@ -23,9 +23,14 @@
|
|||
*/
|
||||
package paint;
|
||||
|
||||
import javax.swing.JColorChooser;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.colorchooser.DefaultColorSelectionModel;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -50,75 +55,42 @@ public class Paint extends javax.swing.JFrame {
|
|||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
paint = new paint.PaintPanel();
|
||||
jPanel1 = new javax.swing.JPanel();
|
||||
jLabel1 = new javax.swing.JLabel();
|
||||
jToolBar1 = new javax.swing.JToolBar();
|
||||
jButton17 = new javax.swing.JButton();
|
||||
jButton12 = new javax.swing.JButton();
|
||||
jButton16 = new javax.swing.JButton();
|
||||
jSeparator1 = new javax.swing.JToolBar.Separator();
|
||||
jButton5 = new javax.swing.JButton();
|
||||
jButton6 = new javax.swing.JButton();
|
||||
jButton7 = new javax.swing.JButton();
|
||||
jButton8 = new javax.swing.JButton();
|
||||
jButton9 = new javax.swing.JButton();
|
||||
jButton10 = new javax.swing.JButton();
|
||||
jSeparator2 = new javax.swing.JToolBar.Separator();
|
||||
jButton13 = new javax.swing.JButton();
|
||||
jButton14 = new javax.swing.JButton();
|
||||
jSeparator3 = new javax.swing.JToolBar.Separator();
|
||||
jButton1 = new javax.swing.JButton();
|
||||
jButton2 = new javax.swing.JButton();
|
||||
jButton3 = new javax.swing.JButton();
|
||||
jButton4 = new javax.swing.JButton();
|
||||
jButton11 = new javax.swing.JButton();
|
||||
jSeparator4 = new javax.swing.JToolBar.Separator();
|
||||
jToggleButton1 = new javax.swing.JToggleButton();
|
||||
jButton10 = new javax.swing.JButton();
|
||||
jButton15 = new javax.swing.JButton();
|
||||
pan = new javax.swing.JPanel();
|
||||
scroll = new javax.swing.JScrollPane();
|
||||
paint = new paint.PaintPanel();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
|
||||
paint.setBackground(new java.awt.Color(255, 255, 255));
|
||||
|
||||
jPanel1.setBackground(new java.awt.Color(123, 189, 254));
|
||||
|
||||
jLabel1.setFont(new java.awt.Font("Noto Sans", 0, 18)); // NOI18N
|
||||
jLabel1.setText("Paint");
|
||||
|
||||
jButton5.setText("pencil");
|
||||
jButton5.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton5ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jButton6.setText("line");
|
||||
jButton6.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton6ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jButton7.setText("rectangle");
|
||||
jButton7.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton7ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jButton8.setText("oval");
|
||||
jButton8.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton8ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jButton9.setText("circle");
|
||||
jButton9.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton9ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jButton10.setBackground(new java.awt.Color(0, 0, 0));
|
||||
jButton10.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton10ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jToggleButton1.setText("filled");
|
||||
jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jToggleButton1ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
|
||||
jPanel1.setLayout(jPanel1Layout);
|
||||
jPanel1Layout.setHorizontalGroup(
|
||||
|
|
@ -126,50 +98,196 @@ public class Paint extends javax.swing.JFrame {
|
|||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(jLabel1)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jButton5)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jButton6)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jButton7)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jButton8)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jButton9)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 181, Short.MAX_VALUE)
|
||||
.addComponent(jToggleButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap())
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
jPanel1Layout.setVerticalGroup(
|
||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel1)
|
||||
.addComponent(jButton5)
|
||||
.addComponent(jButton6)
|
||||
.addComponent(jButton7)
|
||||
.addComponent(jButton8)
|
||||
.addComponent(jButton9)
|
||||
.addComponent(jButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(jToggleButton1))
|
||||
.addGap(0, 0, 0))
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
jToolBar1.setRollover(true);
|
||||
|
||||
jButton17.setText("new");
|
||||
jButton17.setFocusable(false);
|
||||
jButton17.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
|
||||
jButton17.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
|
||||
jButton17.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton17ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jToolBar1.add(jButton17);
|
||||
|
||||
jButton12.setText("save");
|
||||
jButton12.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton12ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jToolBar1.add(jButton12);
|
||||
|
||||
jButton16.setText("open");
|
||||
jButton16.setFocusable(false);
|
||||
jButton16.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
|
||||
jButton16.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
|
||||
jButton16.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton16ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jToolBar1.add(jButton16);
|
||||
jToolBar1.add(jSeparator1);
|
||||
|
||||
jButton5.setText("pencil");
|
||||
jButton5.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton5ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jToolBar1.add(jButton5);
|
||||
|
||||
jButton6.setText("line");
|
||||
jButton6.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton6ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jToolBar1.add(jButton6);
|
||||
|
||||
jButton7.setText("rect");
|
||||
jButton7.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton7ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jToolBar1.add(jButton7);
|
||||
|
||||
jButton8.setText("oval");
|
||||
jButton8.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton8ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jToolBar1.add(jButton8);
|
||||
|
||||
jButton9.setText("circle");
|
||||
jButton9.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton9ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jToolBar1.add(jButton9);
|
||||
jToolBar1.add(jSeparator2);
|
||||
|
||||
jButton13.setText("undo");
|
||||
jButton13.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton13ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jToolBar1.add(jButton13);
|
||||
|
||||
jButton14.setText("redo");
|
||||
jButton14.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton14ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jToolBar1.add(jButton14);
|
||||
jToolBar1.add(jSeparator3);
|
||||
|
||||
jButton1.setText("1");
|
||||
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton1ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jToolBar1.add(jButton1);
|
||||
|
||||
jButton2.setText("2");
|
||||
jButton2.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton2ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jToolBar1.add(jButton2);
|
||||
|
||||
jButton3.setText("3");
|
||||
jButton3.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton3ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jToolBar1.add(jButton3);
|
||||
|
||||
jButton4.setText("4");
|
||||
jButton4.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton4ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jToolBar1.add(jButton4);
|
||||
|
||||
jButton11.setText("5");
|
||||
jButton11.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton11ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jToolBar1.add(jButton11);
|
||||
jToolBar1.add(jSeparator4);
|
||||
|
||||
jToggleButton1.setText("fill");
|
||||
jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jToggleButton1ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jToolBar1.add(jToggleButton1);
|
||||
|
||||
jButton10.setBackground(new java.awt.Color(0, 0, 0));
|
||||
jButton10.setText("F");
|
||||
jButton10.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton10ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jToolBar1.add(jButton10);
|
||||
|
||||
jButton15.setBackground(new java.awt.Color(255, 255, 255));
|
||||
jButton15.setText("B");
|
||||
jButton15.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jButton15ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
jToolBar1.add(jButton15);
|
||||
|
||||
pan.setLayout(new java.awt.BorderLayout());
|
||||
|
||||
paint.setBackground(new java.awt.Color(255, 255, 255));
|
||||
scroll.setViewportView(paint);
|
||||
|
||||
pan.add(scroll, java.awt.BorderLayout.CENTER);
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(paint, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 800, Short.MAX_VALUE)
|
||||
.addComponent(pan, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(0, 0, 0)
|
||||
.addComponent(paint, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE)
|
||||
.addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(0, 0, 0)
|
||||
.addComponent(pan, javax.swing.GroupLayout.DEFAULT_SIZE, 452, Short.MAX_VALUE)
|
||||
.addGap(0, 0, 0))
|
||||
);
|
||||
|
||||
|
|
@ -198,17 +316,88 @@ public class Paint extends javax.swing.JFrame {
|
|||
|
||||
private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
|
||||
ColorChoose ch = new ColorChoose(this, true);
|
||||
ch.col.setColor(paint.color);
|
||||
ch.col.setColor(paint.fcolor);
|
||||
ch.setVisible(true);
|
||||
paint.color = ch.col.getColor();
|
||||
jButton10.setBackground(paint.color);
|
||||
ch.dispose();
|
||||
paint.fcolor = ch.col.getColor();
|
||||
jButton10.setBackground(paint.fcolor);
|
||||
}//GEN-LAST:event_jButton10ActionPerformed
|
||||
|
||||
private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed
|
||||
paint.isfilled = jToggleButton1.isSelected();
|
||||
}//GEN-LAST:event_jToggleButton1ActionPerformed
|
||||
|
||||
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
|
||||
paint.thick = 1;
|
||||
}//GEN-LAST:event_jButton1ActionPerformed
|
||||
|
||||
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
|
||||
paint.thick = 2;
|
||||
}//GEN-LAST:event_jButton2ActionPerformed
|
||||
|
||||
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
|
||||
paint.thick = 3;
|
||||
}//GEN-LAST:event_jButton3ActionPerformed
|
||||
|
||||
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
|
||||
paint.thick = 4;
|
||||
}//GEN-LAST:event_jButton4ActionPerformed
|
||||
|
||||
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
|
||||
paint.thick = 5;
|
||||
}//GEN-LAST:event_jButton11ActionPerformed
|
||||
|
||||
private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
|
||||
paint.save();
|
||||
}//GEN-LAST:event_jButton12ActionPerformed
|
||||
|
||||
private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
|
||||
paint.undo();
|
||||
}//GEN-LAST:event_jButton13ActionPerformed
|
||||
|
||||
private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
|
||||
paint.redo();
|
||||
}//GEN-LAST:event_jButton14ActionPerformed
|
||||
|
||||
private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton15ActionPerformed
|
||||
ColorChoose ch = new ColorChoose(this, true);
|
||||
ch.col.setColor(paint.bcolor);
|
||||
ch.setVisible(true);
|
||||
paint.bcolor = ch.col.getColor();
|
||||
jButton15.setBackground(paint.bcolor);
|
||||
ch.dispose();
|
||||
}//GEN-LAST:event_jButton15ActionPerformed
|
||||
|
||||
private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton16ActionPerformed
|
||||
FileDialog fd = new FileDialog(this, "open", FileDialog.LOAD);
|
||||
fd.setVisible(true);
|
||||
fd.setMultipleMode(false);
|
||||
if(fd.getFiles().length > 0)
|
||||
{
|
||||
File file = fd.getFiles()[0];
|
||||
paint.open(file);
|
||||
repaintWorkArea();
|
||||
}
|
||||
}//GEN-LAST:event_jButton16ActionPerformed
|
||||
|
||||
private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton17ActionPerformed
|
||||
paint.newfile();
|
||||
repaintWorkArea();
|
||||
}//GEN-LAST:event_jButton17ActionPerformed
|
||||
|
||||
public void repaintWorkArea()
|
||||
{
|
||||
int w,h;
|
||||
|
||||
if(pan.getWidth() > paint.width) w = paint.width + 3;
|
||||
else w = pan.getWidth();
|
||||
|
||||
if(pan.getHeight() > paint.height) h = paint.height + 3;
|
||||
else h = pan.getHeight();
|
||||
|
||||
scroll.setSize(w, h);
|
||||
scroll.revalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
|
|
@ -223,7 +412,18 @@ public class Paint extends javax.swing.JFrame {
|
|||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton jButton1;
|
||||
private javax.swing.JButton jButton10;
|
||||
private javax.swing.JButton jButton11;
|
||||
private javax.swing.JButton jButton12;
|
||||
private javax.swing.JButton jButton13;
|
||||
private javax.swing.JButton jButton14;
|
||||
private javax.swing.JButton jButton15;
|
||||
private javax.swing.JButton jButton16;
|
||||
private javax.swing.JButton jButton17;
|
||||
private javax.swing.JButton jButton2;
|
||||
private javax.swing.JButton jButton3;
|
||||
private javax.swing.JButton jButton4;
|
||||
private javax.swing.JButton jButton5;
|
||||
private javax.swing.JButton jButton6;
|
||||
private javax.swing.JButton jButton7;
|
||||
|
|
@ -231,7 +431,14 @@ public class Paint extends javax.swing.JFrame {
|
|||
private javax.swing.JButton jButton9;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
private javax.swing.JPanel jPanel1;
|
||||
private javax.swing.JToolBar.Separator jSeparator1;
|
||||
private javax.swing.JToolBar.Separator jSeparator2;
|
||||
private javax.swing.JToolBar.Separator jSeparator3;
|
||||
private javax.swing.JToolBar.Separator jSeparator4;
|
||||
private javax.swing.JToggleButton jToggleButton1;
|
||||
private javax.swing.JToolBar jToolBar1;
|
||||
private paint.PaintPanel paint;
|
||||
private javax.swing.JPanel pan;
|
||||
private javax.swing.JScrollPane scroll;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,13 +23,22 @@
|
|||
*/
|
||||
package paint;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -37,24 +46,42 @@ import java.util.ArrayList;
|
|||
*/
|
||||
public class PaintPanel extends Component implements MouseMotionListener, MouseListener
|
||||
{
|
||||
public ArrayList<Part> parts = new ArrayList<>();
|
||||
public Color color = Color.BLACK;
|
||||
public String shape = "pencil";
|
||||
public Boolean isfilled = false;
|
||||
public int width , height;
|
||||
public Color fcolor;
|
||||
public Color bcolor;
|
||||
public String shape;
|
||||
public Boolean isfilled;
|
||||
public int thick;
|
||||
public BufferedImage it;
|
||||
private ArrayList<Part> parts;
|
||||
private ArrayList<Part> undo;
|
||||
private Graphics2D gt;
|
||||
|
||||
public PaintPanel()
|
||||
{
|
||||
width = 600;
|
||||
height = 300;
|
||||
parts = new ArrayList<>();
|
||||
undo = new ArrayList<>();
|
||||
fcolor = Color.BLACK;
|
||||
bcolor = Color.WHITE;
|
||||
shape = "pencil";
|
||||
isfilled = false;
|
||||
thick = 1;
|
||||
it = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
gt = it.createGraphics();
|
||||
gt.setColor(Color.white);
|
||||
gt.fillRect(0, 0, width, height);
|
||||
|
||||
this.addMouseListener(this);
|
||||
this.addMouseMotionListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g)
|
||||
public void draw(Graphics2D gr, Part part)
|
||||
{
|
||||
for(Part part : parts)
|
||||
{
|
||||
g.setColor(part.color);
|
||||
|
||||
gr.setColor(part.fcolor);
|
||||
gr.setStroke(new java.awt.BasicStroke(part.thick));
|
||||
if(part.shape.equals("pencil"))
|
||||
{
|
||||
int x = part.cords.get(0).x;
|
||||
|
|
@ -63,14 +90,14 @@ public class PaintPanel extends Component implements MouseMotionListener, MouseL
|
|||
|
||||
for(int i = 1; i < part.cords.size(); i++)
|
||||
{
|
||||
g.drawLine(x, y, part.cords.get(i).x, part.cords.get(i).y);
|
||||
gr.drawLine(x, y, part.cords.get(i).x, part.cords.get(i).y);
|
||||
x = part.cords.get(i).x;
|
||||
y = part.cords.get(i).y;
|
||||
}
|
||||
}
|
||||
else if(part.shape.equals("line"))
|
||||
{
|
||||
if(part.cords.size() > 1) g.drawLine(part.cords.get(0).x, part.cords.get(0).y, part.cords.get(1).x, part.cords.get(1).y);
|
||||
if(part.cords.size() > 1) gr.drawLine(part.cords.get(0).x, part.cords.get(0).y, part.cords.get(1).x, part.cords.get(1).y);
|
||||
}
|
||||
else if(part.shape.equals("rect"))
|
||||
{
|
||||
|
|
@ -81,8 +108,13 @@ public class PaintPanel extends Component implements MouseMotionListener, MouseL
|
|||
y1 = Math.min(part.cords.get(0).y, part.cords.get(1).y);
|
||||
x2 = Math.max(part.cords.get(0).x, part.cords.get(1).x);
|
||||
y2 = Math.max(part.cords.get(0).y, part.cords.get(1).y);
|
||||
if(part.isfilled) g.fillRect(x1,y1,x2 - x1,y2 - y1);
|
||||
else g.drawRect(x1,y1,x2 - x1,y2 - y1);
|
||||
if(part.isfilled) {
|
||||
gr.setColor(part.bcolor);
|
||||
gr.fillRect(x1,y1,x2 - x1,y2 - y1);
|
||||
gr.setColor(part.fcolor);
|
||||
gr.drawRect(x1,y1,x2 - x1,y2 - y1);
|
||||
}
|
||||
else gr.drawRect(x1,y1,x2 - x1,y2 - y1);
|
||||
}
|
||||
}
|
||||
else if(part.shape.equals("oval"))
|
||||
|
|
@ -94,8 +126,13 @@ public class PaintPanel extends Component implements MouseMotionListener, MouseL
|
|||
y1 = Math.min(part.cords.get(0).y, part.cords.get(1).y);
|
||||
x2 = Math.max(part.cords.get(0).x, part.cords.get(1).x);
|
||||
y2 = Math.max(part.cords.get(0).y, part.cords.get(1).y);
|
||||
if(part.isfilled) g.fillOval(x1,y1,x2 - x1,y2 - y1);
|
||||
else g.drawOval(x1,y1,x2 - x1,y2 - y1);
|
||||
if(part.isfilled) {
|
||||
gr.setColor(part.bcolor);
|
||||
gr.fillOval(x1,y1,x2 - x1,y2 - y1);
|
||||
gr.setColor(part.fcolor);
|
||||
gr.drawOval(x1,y1,x2 - x1,y2 - y1);
|
||||
}
|
||||
else gr.drawOval(x1,y1,x2 - x1,y2 - y1);
|
||||
}
|
||||
}
|
||||
else if(part.shape.equals("circle"))
|
||||
|
|
@ -108,11 +145,105 @@ public class PaintPanel extends Component implements MouseMotionListener, MouseL
|
|||
x2 = Math.max(part.cords.get(0).x, part.cords.get(1).x);
|
||||
y2 = Math.max(part.cords.get(0).y, part.cords.get(1).y);
|
||||
r = (int)Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
|
||||
if(part.isfilled) g.fillOval(part.cords.get(0).x - r,part.cords.get(0).y - r,2 * r,2 * r);
|
||||
else g.drawOval(part.cords.get(0).x - r,part.cords.get(0).y - r,2 * r,2 * r);
|
||||
if(part.isfilled) {
|
||||
gr.setColor(part.bcolor);
|
||||
gr.fillOval(part.cords.get(0).x - r,part.cords.get(0).y - r,2 * r,2 * r);
|
||||
gr.setColor(part.fcolor);
|
||||
gr.drawOval(part.cords.get(0).x - r,part.cords.get(0).y - r,2 * r,2 * r);
|
||||
}
|
||||
else gr.drawOval(part.cords.get(0).x - r,part.cords.get(0).y - r,2 * r,2 * r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void paintToBuffer()
|
||||
{
|
||||
if(parts.size() > 10)
|
||||
{
|
||||
Part part = parts.get(0);
|
||||
draw(gt, part);
|
||||
parts.remove(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
BufferedImage buf = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g = buf.createGraphics();
|
||||
g.drawImage(it, 0,0,null);
|
||||
for(Part part : parts)
|
||||
{
|
||||
draw(g, part);
|
||||
}
|
||||
try {
|
||||
ImageIO.write(buf, "png", new File("image.png"));
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(PaintPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void open(File file)
|
||||
{
|
||||
BufferedImage buff = null;
|
||||
try {
|
||||
buff = ImageIO.read(file);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(Paint.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
width = buff.getWidth();
|
||||
height = buff.getHeight();
|
||||
this.setPreferredSize(new Dimension(width, height));
|
||||
it = buff;
|
||||
parts = new ArrayList<>();
|
||||
undo = new ArrayList<>();
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
public void newfile()
|
||||
{
|
||||
parts = new ArrayList<>();
|
||||
undo = new ArrayList<>();
|
||||
it = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
gt = it.createGraphics();
|
||||
gt.setColor(Color.white);
|
||||
gt.fillRect(0, 0, width, height);
|
||||
width = 600;
|
||||
height = 300;
|
||||
this.setSize(new Dimension(width, height));
|
||||
this.repaint();
|
||||
}
|
||||
|
||||
public void undo()
|
||||
{
|
||||
if(parts.size() > 0)
|
||||
{
|
||||
undo.add(parts.get(parts.size()-1));
|
||||
parts.remove(parts.size()-1);
|
||||
this.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
public void redo()
|
||||
{
|
||||
if(undo.size() > 0)
|
||||
{
|
||||
parts.add(undo.get(undo.size()-1));
|
||||
undo.remove(undo.size()-1);
|
||||
this.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g)
|
||||
{
|
||||
Graphics2D gr = (Graphics2D)g;
|
||||
gr.drawImage(it, 0,0,null);
|
||||
for(Part part : parts)
|
||||
{
|
||||
draw(gr, part);
|
||||
}
|
||||
|
||||
paintToBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -138,7 +269,8 @@ public class PaintPanel extends Component implements MouseMotionListener, MouseL
|
|||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
parts.add(new Part(shape, color,isfilled));
|
||||
if(undo.size() > 0) undo = new ArrayList<>();
|
||||
parts.add(new Part(shape, fcolor, bcolor,isfilled, thick));
|
||||
parts.get(parts.size() - 1).cords.add(new Cord(e.getX(), e.getY()));
|
||||
this.repaint();
|
||||
}
|
||||
|
|
@ -169,29 +301,37 @@ class Part
|
|||
{
|
||||
String shape;
|
||||
ArrayList<Cord> cords;
|
||||
Color color;
|
||||
Color fcolor;
|
||||
Color bcolor;
|
||||
int thick;
|
||||
Boolean isfilled;
|
||||
|
||||
public Part()
|
||||
{
|
||||
this.shape = "pencil";
|
||||
this.cords = new ArrayList<>();
|
||||
this.color = Color.black;
|
||||
this.fcolor = Color.black;
|
||||
this.bcolor = Color.white;
|
||||
this.isfilled = false;
|
||||
this.thick = 1;
|
||||
}
|
||||
public Part(String shape, Color color, Boolean isfilled)
|
||||
public Part(String shape, Color fcolor,Color bcolor, Boolean isfilled, int thick)
|
||||
{
|
||||
this.shape = shape;
|
||||
this.cords = new ArrayList<>();
|
||||
this.color = color;
|
||||
this.fcolor = fcolor;
|
||||
this.bcolor = bcolor;
|
||||
this.isfilled = isfilled;
|
||||
this.thick = thick;
|
||||
}
|
||||
public Part(String shape, ArrayList<Cord> cords, Color color, Boolean isfilled)
|
||||
public Part(String shape, ArrayList<Cord> cords, Color color, Boolean isfilled, int thick)
|
||||
{
|
||||
this.shape = shape;
|
||||
this.cords = cords;
|
||||
this.color = color;
|
||||
this.fcolor = color;
|
||||
this.bcolor = bcolor;
|
||||
this.isfilled = isfilled;
|
||||
this.thick = thick;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue