hello this is my first post i have a project to do but i have problems with the code
the programm work without any error but i dont understand why some features doesnt work plz help
so i have to make a programma that get an image and resize alling left right center have optrion button and can reset this is the code plz some help me.So if someone know the problem plz explain to me too im getting crazy when im running the programm i can reset it resize the image but i cannot aling left right center
this is the code
import java.awt.*; import java.awt.Graphics; import java.awt.Dimension; import java.awt.event.*; import javax.swing.*; import javax.swing.JFrame; import javax.swing.ImageIcon; import javax.swing.Icon.*; import java.lang.Object; import java.awt.image.BufferedImage; import java.awt.Image; import java.awt.BorderLayout; import java.awt.Graphics2D; import java.awt.Graphics; import java.awt.image.BufferedImage; public class Image_Application extends JFrame { private MyPanel p1; private JPanel p2,p3; private JTextField t1, t2; private JButton alignL, alignC, alignR,resize; public Image_Application() { super("Image Application"); p1=new MyPanel(); Container c=getContentPane(); c.add(p1, BorderLayout.CENTER); alignL = new JButton("Align Left"); alignC = new JButton("Align Center"); alignR = new JButton("Align Right"); resize= new JButton("Resize"); JPanel north = new JPanel(); north.add(alignL); north.add(alignC); north.add(alignR); c.add(north, BorderLayout.NORTH); p2=new JPanel(); // JPanel width = new JPanel("Width: "); t1=new JTextField(10); t1.setText(String.valueOf((int)p1.getImageIconDimension().getWidth())); // JPanel length = new JPanel("Heigth: "); t2=new JTextField(10); t2.setText(String.valueOf((int)p1.getImageIconDimension().getHeight())); p2.setLayout(new FlowLayout()); p2.add(resize); c.add(p2, BorderLayout.SOUTH); p3=new JPanel(); p3.setLayout(new GridLayout(2,1)); p3.add(t1); p3.add(t2); c.add(p3, BorderLayout.EAST); resize.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { p1.scale(Integer.parseInt(t1.getText()),Integer.parseInt(t2.getText())); } }); alignL.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent a) { p1.setLayout(new FlowLayout(FlowLayout.LEFT)); p1.validate(); } }); alignR.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { p1.setLayout(new FlowLayout(FlowLayout.RIGHT)); p1.validate(); } }); alignC.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { getContentPane().setLayout(new BorderLayout()); getContentPane().add(p1, BorderLayout.CENTER); p1.validate(); } }); JMenuBar mb=new JMenuBar(); JMenu m=new JMenu("Options"); JMenuItem mi1=new JMenuItem("Resize"); mi1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ p1.scale(Integer.parseInt(t1.getText()),Integer.parseInt(t2.getText())); } }); JMenuItem mi2=new JMenuItem("Reset"); mi2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {p1.setOriginalSize();} } ); m.add(mi1); m.add(mi2); mb.add(m); setJMenuBar(mb); setSize(400,300); setVisible(true); } public static void main(String args[]) { Image_Application a=new Image_Application(); a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } class MyPanel extends JPanel { private ImageIcon ic; public MyPanel() { setOriginalSize();} public void paintComponent(Graphics g) { super.paintComponent(g); ic.paintIcon(this,g,0,0); } public void scale(int w, int h) { ic=new ImageIcon(ic.getImage().getScaledInstance(w,h,Image.SCALE_FAST)); repaint(); } public void setOriginalSize() { ic=new ImageIcon("tulips.jpg"); repaint(); } public Dimension getImageIconDimension() { return new Dimension(ic.getIconWidth(), ic.getIconHeight()); } }