Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
216 views
in Technique[技术] by (71.8m points)

java - Painting in a BufferedImage inside Swing

Im working on a paint application written in java and running into a few (more) problems. I have a gui and a working program(kinda), my only problem is that the lines and graphics that the user draws are not saved(disappear after next one is drawn).

From a past question i learned that i will need to use a BufferedImage to store the drawings then paint that inside my paint class.

My questions are, Can anyone provide a basic explanation/example of how to use a bufferedimage to store and paint the drawing and if i need to, how will i pass the color and thickness of the drawn line into a stored array.

thats my whole class.

package javapaint;

import java.awt.*;
import javax.swing.*;

public class JavaPaintUI extends javax.swing.JFrame {

/** Creates new form JavaPaintUI */
public JavaPaintUI() {
    initComponents();
}

// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    buttonGroup1 = new javax.swing.ButtonGroup();
    buttonGroup2 = new javax.swing.ButtonGroup();
    jPanel4 = new javax.swing.JPanel();
    jRadioButton9 = new javax.swing.JRadioButton();
    jRadioButton10 = new javax.swing.JRadioButton();
    jSlider2 = new javax.swing.JSlider();
    jLabel1 = new javax.swing.JLabel();
    jPanel2 = new Panel2();
    jPanel3 = new javax.swing.JPanel();
    jRadioButton3 = new javax.swing.JRadioButton();
    jRadioButton4 = new javax.swing.JRadioButton();
    jRadioButton5 = new javax.swing.JRadioButton();
    jRadioButton6 = new javax.swing.JRadioButton();
    jRadioButton7 = new javax.swing.JRadioButton();
    jRadioButton8 = new javax.swing.JRadioButton();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("JavaPaint ~ Nick R");

    jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Tool"));

    buttonGroup1.add(jRadioButton9);
    jRadioButton9.setText("Pen");
    jRadioButton9.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jRadioButton9ActionPerformed(evt);
        }
    });

    buttonGroup1.add(jRadioButton10);
    jRadioButton10.setText("Line");
    jRadioButton10.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jRadioButton10ActionPerformed(evt);
        }
    });

    jSlider2.setMajorTickSpacing(10);
    jSlider2.setMaximum(51);
    jSlider2.setMinimum(1);
    jSlider2.setMinorTickSpacing(5);
    jSlider2.setPaintTicks(true);
    jSlider2.addChangeListener(new javax.swing.event.ChangeListener() {
        public void stateChanged(javax.swing.event.ChangeEvent evt) {
            jSlider2StateChanged(evt);
        }
    });

    jLabel1.setText("Stroke Size (Radius)");

    javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
    jPanel4.setLayout(jPanel4Layout);
    jPanel4Layout.setHorizontalGroup(
        jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel4Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jRadioButton9)
                .addComponent(jRadioButton10))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(jLabel1)
                .addComponent(jSlider2, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap())
    );
    jPanel4Layout.setVerticalGroup(
        jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
            .addComponent(jSlider2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton9)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jRadioButton10)))
    );

    jPanel2.setBackground(new java.awt.Color(255, 255, 255));
    jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
    jPanel2.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mousePressed(java.awt.event.MouseEvent evt) {
            jPanel2MousePressed(evt);
        }
        public void mouseReleased(java.awt.event.MouseEvent evt) {
            jPanel2MouseReleased(evt);
        }
    });
    jPanel2.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
        public void mouseDragged(java.awt.event.MouseEvent evt) {
            jPanel2MouseDragged(evt);
        }
    });

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 596, Short.MAX_VALUE)
    );
    jPanel2Layout.setVerticalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 357, Short.MAX_VALUE)
    );

    jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Color"));

    buttonGroup2.add(jRadioButton3);
    jRadioButton3.setText("Red");
    jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jRadioButton3ActionPerformed(evt);
        }
    });

    buttonGroup2.add(jRadioButton4);
    jRadioButton4.setText("Black");
    jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jRadioButton4ActionPerformed(evt);
        }
    });

    buttonGroup2.add(jRadioButton5);
    jRadioButton5.setText("Gray");
    jRadioButton5.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jRadioButton5ActionPerformed(evt);
        }
    });

    buttonGroup2.add(jRadioButton6);
    jRadioButton6.setText("Green");
    jRadioButton6.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jRadioButton6ActionPerformed(evt);
        }
    });

    buttonGroup2.add(jRadioButton7);
    jRadioButton7.setText("White");
    jRadioButton7.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jRadioButton7ActionPerformed(evt);
        }
    });

    buttonGroup2.add(jRadioButton8);
    jRadioButton8.setText("Blue");
    jRadioButton8.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jRadioButton8ActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(
        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel3Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(jRadioButton3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jRadioButton4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jRadioButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE)
                .addComponent(jRadioButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                .addComponent(jRadioButton8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jRadioButton7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addContainerGap())
    );
    jPanel3Layout.setVerticalGroup(
        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jRadioButton4)
                .addComponent(jRadioButton5)
                .addComponent(jRadioButton7))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 3, Short.MAX_VALUE)
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jRadioButton3)
                .addComponent(jRadioButton6)
                .addComponent(jRadioButton8)))
    );

    jButton1.setText("Clear");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    jButton2.setText("About");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton2ActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayo

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

OK - here are a ..few changes.

import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;

public class JavaPaintUI extends JFrame {

    private BufferedImage canvas;

/** Creates new form JavaPaintUI */
public JavaPaintUI() {
    initComponents();
}

    //this was moved from the overriden paintComponent()
    // instead it update the canvas BufferedImage and calls repaint()
    public void updateCanvas() {
        Graphics2D g2d = canvas.createGraphics();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

        g2d.setPaint( getColor() );

        if (tool == 1) {

            g2d.fillOval(currentX - ((int) value / 2), currentY - ((int) value / 2), (int) value, (int) value);
        } else if (tool == 2) {
            g2d.setStroke(new BasicStroke((float) value, BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
            g2d.drawLine(oldX, oldY, currentX, currentY);
            g2d.setStroke(new BasicStroke(1.0f));
        }
        repaint();
    }

    // used in both the updateCanvas and 'clear' method.
    private Color getColor() {
        Color c = null;
       if(color==1)
        c = Color.black;
        else if(color==2)
        c = Color.gray;
        else if(color==3)
        c = Color.white;
        else if(color==4)
        c = Color.red;
        else if(color==5)
        c = Color.green;
        else if(color==6)
        c = Color.blue;

        return c;
    }

// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

    canvas = new BufferedImage(600,400,BufferedImage.TYPE_INT_RGB);

    buttonGroup1 = new ButtonGroup();
    buttonGroup2 = new ButtonGroup();
    jPanel4 = new JPanel();
    jRadioButton9 = new JRadioButton();
    jRadioButton10 = new JRadioButton();
    jSlider2 = new JSlider();
    jLabel1 = new JLabel();
    jPanel2 = new JPanel(new GridBagLayout());
    JLabel canvasLabel = new JLabel(new ImageIcon(canvas));
    jPanel2.add(canvasLabel, null);

    jPanel3 = new JPanel();
    jRadioButton3 = new JRadioButton();
    jRadioButton4 = new JRadioButton();
    jRadioButton5 = new JRadioButton();
    jRadioButton6 = new JRadioButton();
    jRadioButton7 = new JRadioButton();
    jRadioButton8 = new JRadioButton();
    jButton1 = new JButton();
    jButton2 = new JButton();

    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setTitle("JavaPaint ~ Nick R");

    jPanel4.setBorder(BorderFactory.createTitledBorder("Tool"));

    buttonGroup1.add(jRadioButton9);
    jRadioButton9.setText("Pen");
    jRadioButton9.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            jRadioButton9ActionPerformed(evt);
        }
    });

    buttonGroup1.add(jRadioButton10);
    jRadioButton10.setText("Line");
    jRadioButton10.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            jRadioButton10ActionPerformed(evt);
        }
    });

    jSlider2.setMajorTickSpacing(10);
    jSlider2.setMaximum(51);
    jSlider2.setMinimum(1);
    jSlider2.setMinorTickSpacing(5);
    jSlider2.setPaintTicks(true);
    jSlider2.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent evt) {
            jSlider2StateChanged(evt);
        }
    });

    jLabel1.setText("Stroke Size (Radius)");

    GroupLayout jPanel4Layout = new GroupLayout(jPanel4);
    jPanel4.setLayout(jPanel4Layout);
    jPanel4Layout.setHorizontalGroup(
        jPanel4Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(jPanel4Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel4Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addComponent(jRadioButton9)
                .addComponent(jRadioButton10))
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
            .addGroup(jPanel4Layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                .addComponent(jLabel1)
                .addComponent(jSlider2, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE))
            .addContainerGap())
    );
    jPanel4Layout.setVerticalGroup(
        jPanel4Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(jPanel4Layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
            .addComponent(jSlider2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButton9)
                    .addComponent(jLabel1))
                .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jRadioButton10)))
    );

    jPanel2.setBackground(new Color(128, 40, 128));
    jPanel2.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    // add the listeners to the label that contains the canvas buffered image
    canvasLabel.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent evt) {
            jPanel2MousePressed(evt);
        }
        public void mouseReleased(MouseEvent evt) {
            jPanel2MouseReleased(evt);
        }
    });
    canvasLabel.addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent evt) {
            jPanel2MouseDragged(evt);
        }
    });

    // this part of the code was not helping.
    // either layout a container or custom paint it.
    // only attempt both if you are very confident of what you are doing.
/*
    GroupLayout jPanel2Layout = new GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
        jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGap(0, 596, Short.MAX_VALUE)
    );
    jPanel2Layout.setVerticalGroup(
        jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGap(0, 357, Short.MAX_VALUE)
    );
*/
    jPanel3.setBorder(BorderFactory.createTitledBorder("Color"));

    buttonGroup2.add(jRadioButton3);
    jRadioButton3.setText("Red");
    jRadioButton3.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            jRadioButton3ActionPerformed(evt);
        }
    });

    buttonGroup2.add(jRadioButton4);
    jRadioButton4.setText("Black");
    jRadioButton4.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            jRadioButton4ActionPerformed(evt);
        }
    });

    buttonGroup2.add(jRadioButton5);
    jRadioButton5.setText("Gray");
    jRadioButton5.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            jRadioButton5ActionPerformed(evt);
        }
    });

    buttonGroup2.add(jRadioButton6);
    jRadioButton6.setText("Green");
    jRadioButton6.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            jRadioButton6ActionPerformed(evt);
        }
    });

    buttonGroup2.add(jRadioButton7);
    jRadioButton7.setText("White");
    jRadioButton7.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            jRadioButton7ActionPerformed(evt);
        }
    });

    buttonGroup2.add(jRadioButton8);
    jRadioButton8.setText("Blue");
    jRadioButton8.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            jRadioButton8ActionPerformed(evt);
        }
    });

    GroupLayout jPanel3Layout = new GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(
        jPanel3Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(jPanel3Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel3Layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                .addComponent(jRadioButton3, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jRadioButton4, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE))
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel3Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addComponent(jRadioButton5, GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE)
                .addComponent(jRadioButton6, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel3Layout.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
                .addComponent(jRadioButton8, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jRadioButton7, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addContainerGap())
    );
    jPanel3Layout.setVerticalGroup(
        jPanel3Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
            .addGroup(jPanel3Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(jRadioButton4)
                .addComponent(jRadioButton5)
                .addComponent(jRadioButton7))
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 3, Short.MAX_VALUE)
            .addGroup(jPanel3Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                .addComponent(jRadioButton3)
                .addComponent(jRadioButton6)
                .addComponent(jRadioButton8)))
    );

    jButton1.setText("Clear");
    jButton1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    jButton2.setText("About");
    jButton2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            jButton2ActionPerformed(evt);
        }
    });

    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addComponent(jPanel2, GroupLayout.Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jPanel4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jPanel3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addComponent(jButton2, GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
                        .addComponent(jButton1, GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE))))
            .addContainerGap())
    );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...