import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
public class input_image extends javax.swing.JFrame
{
public static Icon full_image=null; //Image transferred to other class
public input_image()
{
initComponents();
setLocationRelativeTo(null);
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
imagechooser = new javax.swing.JFileChooser();
input_image_panel = new javax.swing.JPanel();
imagescreen = new javax.swing.JLabel();
seperator = new javax.swing.JSeparator();
browse = new javax.swing.JButton();
exit = new javax.swing.JButton();
path = new javax.swing.JLabel();
imagename = new javax.swing.JLabel();
tester = new javax.swing.JLabel();
imagechooser.setApproveButtonText("Select");
imagechooser.setBackground(java.awt.Color.white);
imagechooser.setCurrentDirectory(new java.io.File("C:\\"));
imagechooser.setDialogTitle("Select Image from Disk");
imagechooser.setToolTipText("");
imagechooser.setMaximumSize(new java.awt.Dimension(512, 452));
imagechooser.setMinimumSize(new java.awt.Dimension(400, 250));
imagechooser.setPreferredSize(new java.awt.Dimension(512, 452));
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Select an image");
setName(""); // NOI18N
setUndecorated(true);
input_image_panel.setBackground(new java.awt.Color(175, 175, 240));
input_image_panel.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(0, 0, 0)));
input_image_panel.setPreferredSize(new java.awt.Dimension(543, 345));
imagescreen.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
imagescreen.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent evt) {
imagescreenMouseEntered(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt) {
imagescreenMouseExited(evt);
}
});
browse.setMnemonic('B');
browse.setText("Browse...");
browse.setToolTipText("Click to Browse");
browse.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
browse.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
browseActionPerformed(evt);
}
});
exit.setMnemonic('E');
exit.setText("Exit");
exit.setToolTipText("Click to Exit");
exit.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
exit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitActionPerformed(evt);
}
});
imagename.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
tester.setEnabled(false);
javax.swing.GroupLayout input_image_panelLayout = new javax.swing.GroupLayout(input_image_panel);
input_image_panel.setLayout(input_image_panelLayout);
input_image_panelLayout.setHorizontalGroup(
input_image_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(input_image_panelLayout.createSequentialGroup()
.addGroup(input_image_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(input_image_panelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(seperator, javax.swing.GroupLayout.DEFAULT_SIZE, 519, Short.MAX_VALUE))
.addGroup(input_image_panelLayout.createSequentialGroup()
.addGap(71, 71, 71)
.addComponent(tester)
.addGap(62, 62, 62)
.addGroup(input_image_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(input_image_panelLayout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(imagename, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(imagescreen, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, input_image_panelLayout.createSequentialGroup()
.addGap(32, 32, 32)
.addComponent(path, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(browse)
.addGap(63, 63, 63))
.addGroup(input_image_panelLayout.createSequentialGroup()
.addGap(242, 242, 242)
.addComponent(exit)
.addContainerGap(246, Short.MAX_VALUE))
);
input_image_panelLayout.setVerticalGroup(
input_image_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(input_image_panelLayout.createSequentialGroup()
.addGroup(input_image_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(input_image_panelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(imagescreen, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(imagename, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(input_image_panelLayout.createSequentialGroup()
.addGap(81, 81, 81)
.addComponent(tester)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(seperator, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(input_image_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(browse)
.addComponent(path, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(27, 27, 27)
.addComponent(exit)
.addContainerGap(29, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(input_image_panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(input_image_panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
pack();
}// </editor-fold>
private void exitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void browseActionPerformed(java.awt.event.ActionEvent evt) {
FileReader reader = null;
if(imagechooser.showOpenDialog(null)==JFileChooser.APPROVE_OPTION)
{
File get_image = imagechooser.getSelectedFile();
try
{
reader = new FileReader(get_image);
}
catch (FileNotFoundException ex)
{
Logger.getLogger(input_image.class.getName()).log(Level.SEVERE, null, ex);
}
String value=get_image.toString();
path.setText(value);
ImageIcon icon = new ImageIcon(value);
imagescreen.setIcon(icon);
if(!
(
(value.endsWith(".jpg"))
||
(value.endsWith(".bmp"))
||
(value.endsWith(".png"))
||
(value.endsWith(".jpeg"))
||
(value.endsWith(".JPG"))
||
(value.endsWith(".BMP"))
||
(value.endsWith(".PNG"))
||
(value.endsWith(".JPEG"))
)
)
{
msgbox_invalid_image.main(null);
}
if(imagechooser.getSelectedFile()!=null)
{
imagename.setText(imagechooser.getSelectedFile().getName());
}
full_image=imagescreen.getIcon(); //Stored image in full_image
}
}
msgbox_full_image show_img=new msgbox_full_image(); // Created object of other class
private void imagescreenMouseEntered(java.awt.event.MouseEvent evt) {
if(imagechooser.getSelectedFile()!=null)
{
show_img.setVisible(true); //Called object of other class
}
}
private void imagescreenMouseExited(java.awt.event.MouseEvent evt) {
if(imagechooser.getSelectedFile()!=null)
{
show_img.setVisible(false); //Called object of other class
}
}
public static void main(String args[])
{
java.awt.EventQueue.invokeLater(new Runnable()
{
@Override
public void run()
{
new input_image().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton browse;
private javax.swing.JButton exit;
private javax.swing.JFileChooser imagechooser;
private javax.swing.JLabel imagename;
private javax.swing.JLabel imagescreen;
private javax.swing.JPanel input_image_panel;
private javax.swing.JLabel path;
private javax.swing.JSeparator seperator;
private javax.swing.JLabel tester;
// End of variables declaration
}