Jump to content

Recommended Posts

Posted (edited)

Hi all i am working on a java project this is my code:

 

 

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

import java.awt.BorderLayout;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.ArrayList;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JTextField;

public class Image extends JFrame {

private JButton AlignLeft,AlignRight,AlignCenter,Resize;

public Image (String title){

super (title);

Container contentPane = getContentPane();

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel panel = new JPanel();

 

ImageIcon icon = new ImageIcon("icon_01.jpg");

JLabel label = new JLabel();

label.setIcon(icon);

panel.add(label);

getContentPane().add(panel);

AlignLeft=new JButton("Align Left");

AlignCenter=new JButton("Align Center");

AlignRight=new JButton("Align Right");

Resize=new JButton("Resize");

JPanel north=new JPanel();

JPanel south=new JPanel();

JLabel Width = new JLabel("Width: ",Label.RIGHT);

JTextField txt = new JTextField(17);

JLabel Height=new JLabel("Height: ", Label.RIGHT);

JTextField TxT =new JTextField(17);

north.add(AlignLeft);

north.add(AlignCenter);

north.add(AlignRight);

south.add(Width);

south.add(txt);

south.add(Height);

south.add(TxT);

contentPane.add(north, BorderLayout.NORTH);

contentPane.add(south,BorderLayout.SOUTH);

south.setLayout(new GridLayout(3,2));

south.add(Resize);

JMenuBar menuBar=new JMenuBar();

setJMenuBar(menuBar);

JMenu optionMenu =new JMenu("Options");

menuBar.add(optionMenu);

JMenuItem reset =new JMenuItem("Reset");

optionMenu.add(reset);

add(panel);

pack();

setVisible(true);

}

protected static ImageIcon createImageIcon(String path) {

java.net.URL imgURL = Image.class.getResource(path);

if (imgURL != null) {

return new ImageIcon(imgURL);

} else {

System.err.println("Couldn't find file: " + path);

return null;

}

}

public static void main(String [] arguments){

Image i=new Image("Image Application.");

}

}

 

 

 

 

I want to be able to press any button and do what is made for...

Align Left move picture left

Align Center move picture to the center

Align Right move picture right

Also in the text area i have to put the size of the picture and be able to change it by typing a new size and pressing the button Resize.

 

PLEASE HELP (i am a beginner.... )

Edited by Spyros13

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.