We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

A java paint programme

I have this code and I have been trying to figure it out for a while now but i cant get it to work .My basicproblem is I cant get the paint part or the programme to work properly. I have done several paint programmes in the past but i seem to have forgotten how to make them properly ,anyway heres the code

import java.awt.*;
import java.awt.event.*;
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;
import javax.swing.*;

public class Javamark102 extends JPanel{
    static JFrame rem;
    static Javamark102 soho= new Javamark102();
    static JFileChooser save;
    static JFileChooser open;

            public static void main(String args[]){
                    if(rem==null){
                        rem=new JFrame("Shades");
                    };

                  rem.setSize(500,500);
                  rem.setLocation(1,1);
                  rem.setContentPane(soho);
                  rem.setVisible(true);

                  open();
                 // save();

    };
           JPanel panel=new JPanel();
          static int x;
          static int y;
          static int x2;
          static int y2;

            Javamark102(){
                 setLayout(null);
                 JButton button=new JButton("Save");
             button.addActionListener(new ActionListener(){

            @Override
            public void actionPerformed(ActionEvent e) {
                save();
            }
        });
                 button.setBounds(1000,20,70,30);

              add(button);
           /*  JColorChooser col=new JColorChooser();
                Color select=new Color(col.getColor().getRGB());*/


              // select.setToolTipText("Select Background Color");

                  setBackground(Color.gray);

            /*    this.addMouseListener(new MouseListener(){

            @Override

        });*/

               this.addMouseMotionListener(new MouseAdapter(){
                     public void mouseClicked(MouseEvent e) {
                throw new UnsupportedOperationException("Not supported yet.");
            }

            @Override
            public void mousePressed(MouseEvent e) {
                x=e.getX();
                y=e.getY();
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                throw new UnsupportedOperationException("Not supported yet.");
            }



            @Override
            public void mouseDragged(MouseEvent e) {


                 x=e.getX();
                 y=e.getY();



            }

            @Override
            public void mouseMoved(MouseEvent e) {
                 Graphics2D g2=(Graphics2D) image.getGraphics();
                  g2.setStroke(new BasicStroke(5));
                 x2=x;
                 y2=y;

                g2.drawLine(x, y, x2, y2);
            }
               });



            };
            static BufferedImage image=new BufferedImage(1000,650,BufferedImage.TYPE_INT_ARGB);

             public static void save(){
               if(comand==true){
                   save=new JFileChooser();

               };
               save.showSaveDialog(rem);
        try {
            ImageIO.write(image,"png",new File("logo.png"));
        } catch (IOException ex) {
            Logger.getLogger(Javamark102.class.getName()).log(Level.SEVERE, null, ex);
        }


           };
            static Boolean comand=false;
           public static void open(){
               if(open==null){
                   open=new JFileChooser();

               };
               open.showOpenDialog(rem);
        try {
            image=ImageIO.read(open.getSelectedFile());
        } catch (IOException ex) {
            Logger.getLogger(Javamark102.class.getName()).log(Level.SEVERE, null, ex);
        }

            comand=true;
           };

    @Override
         public void  paintComponent(Graphics g){
               super.paintComponent(g);
                g.drawImage(image, 1 , 1,1000,650, this);
                repaint();

           };


};
2
Contributors
1
Reply
5 Minutes
Discussion Span
8 Months Ago
Last Updated
2
Views
john.mcdonnell.777
Newbie Poster
1 post since Aug 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

I cant get the paint part or the programme to work properly

That's nowhere near enough info. Exact problem please.

JamesCherrill
... trying to help
Moderator
8,496 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,454
Skill Endorsements: 29

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0638 seconds using 2.74MB