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();
};
};