SlideShare a Scribd company logo
I am sorry but my major does not cover programming in depth (ICT) and we are expected to
know advanced java programming. I am looking for help. I have purchased a book from Oracle
but I will not be up to speed this semester. Please Help me!!!
1. Write an app called viewer that will have a Label at the top saying "My Viewer" (or
something like that)
2. Will have JButtons at the bottom that will do Next, Previous, and Quit
3. Have the whole middle be a JLabel in which you will display Images stored in a directory.
4. The directory can be named Resource.
5. When you run the program (java viewer) it will read all the names in the Resource Directory.
Then, when you click Next or Previous it will display an Image.
6. Note: you will need to find a java method that exists for reading a whole directory of
filenames. You can store all those names in a String Array when run the program.
7. You will use a counter or index that is an int an when you click Next it will increment the
counter until it reach some maximum value and then you will set it to 0. Previous will decrement
the counter until it goes negative and then it will set the counter to the Maximum index ( which
is how many filenames you have in the Image names array)
8. Submit the program viewer.java I should be able to use it with my own Resource directory
Solution
Compilation process
javac Viewer.java
Run
java Viewer
Click on next or previous a file chooser will be opened and you can select your file
The Code is in four file.
// File Dg.java
import java.io.File;
public class Dg {
public File nextFile(File file) {
File f[] = new File[5000];
f = file.getParentFile().listFiles(new ImageFileFilter());
int max = f.length;
max = max - 1;
// System.out.println(file);
for (int i = 0; i < f.length; i++) {
if (f[i].equals(file)) {
if (i + 1 > max) {
return f[0];
} else {
return f[i + 1];
}
} else {
// System.out.println(0);
// return file;
}
}
return file;
}
public File priFile(File file) {
File f[] = new File[5000];
f = file.getParentFile().listFiles(new ImageFileFilter());
int min = 0;
// System.out.println(file);
for (int i = 0; i < f.length; i++) {
if (f[i].equals(file)) {
min = i - 1;
if (min < 0) {
return f[f.length-1];
} else {
return f[min];
}
} else {
// System.out.println(0);
// return file;
}
}
return file;
}
}
/// Image.java
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;
public class Image extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
public BufferedImage img = null;
/**
* Create the panel.
*/
@SuppressWarnings("static-access")
public Image() {
setBackground(new Color(255, 255, 255));
setLayout(null);
try {
Viewer ocr = new Viewer();
img = ImageIO.read(ocr.file);
JLabel lblNewLabel = new JLabel(Viewer.file.getName());
lblNewLabel.setFont(new Font("Times New Roman", Font.PLAIN, 18));
lblNewLabel.setBounds(10, 25, 268, 24);
add(lblNewLabel);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public JPanel getPanel(File file) {
JPanel p = new JPanel();
BufferedImage b = null;
try {
b = ImageIO.read(file);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Graphics g = b.getGraphics();
Graphics2D gd = (Graphics2D) g;
gd.drawImage(b, AffineTransform.getScaleInstance(.5, .5), null);
return p;
}
public void paint(Graphics g) {
// TODO Auto-generated method stub
super.paint(g);
// System.out.println("getimage1");
Graphics2D gd = (Graphics2D) g;
int h = img.getHeight();
int w = img.getWidth();
int x1 = 0, x2 = 0, x3 = 0, x4 = 0;
if (h < 550 && w < 1250) {
x1 = (1250 - w) / 2;
x2 = (550 - h) / 2;
x3 = w;
x4 = h;
} else if (h < 550 && w >= 1250) {
x1 = 20;
x2 = (550 - h) / 2;
x3 = 1250;
x4 = (int) (h * (1250.0 / w));
x2 = (550 - x4) / 2;
} else if (h >= 550 && w < 1250) {
x1=(1250-w)/2;
x2=50;
x3=(int) (w*(550.0/h));
x1=(1250-x3)/2;
x4=550;
} else {
x3=(int) (w*(550.0/h));
x4=550;
if(x3>1250)
{
x3=1200;
x4 = (int) (h * (1250.0 / x3));
}
x1 = (1250 - x3) / 2;
x2 = (550 - x4) / 2;
x2=50;
//.out.println(x2);
}
// System.out.println(y1);
// gd.drawImage(img, AffineTransform.getScaleInstance(x1, x1), null);
gd.drawImage(img, x1, x2, x3, x4, null);
}
}
// Viewer.java
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class Viewer {
private JFrame frmImageViewer;
/**
* Launch the application.
*/
JPanel jPanel1 = new JPanel();
JPanel panel = null;
static File file = null;
JButton openButton, saveButton;
JFileChooser fc, fc1;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
Viewer window = new Viewer();
window.frmImageViewer.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Viewer() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
try {
frmImageViewer = new JFrame();
frmImageViewer.setTitle("My Viewer");
// frmImageViewer.getContentPane().setBackground(
// new Color(74, 204, 56));
frmImageViewer.getContentPane().setLayout(null);
JButton btnNewButton = new JButton("Previous");
btnNewButton.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent arg0) {
if (arg0.getExtendedKeyCode() == 37) {
doPri();
}
if (arg0.getExtendedKeyCode() == 39) {
doNext();
}
}
});
btnNewButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
doPri();
}
});
btnNewButton.setBounds(125, 638, 89, 23);
frmImageViewer.getContentPane().add(btnNewButton);
JButton btnNewButton_1 = new JButton("Next");
btnNewButton_1.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent arg0) {
if (arg0.getExtendedKeyCode() == 37) {
System.gc();
doPri();
}
if (arg0.getExtendedKeyCode() == 39) {
System.gc();
doNext();
}
}
});
btnNewButton_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
doNext();
System.gc();
}
});
btnNewButton_1.setBounds(999, 638, 89, 23);
frmImageViewer.getContentPane().add(btnNewButton_1);
JButton button = new JButton("close");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// frmImageViewer.setState(Frame.ICONIFIED);
System.exit(0);
}
});
button.setForeground(new Color(255, 255, 204));
button.setBorder(new LineBorder(new Color(0, 0, 0)));
button.setBackground(new Color(204, 0, 51));
button.setBounds(1271, 0, 95, 25);
frmImageViewer.getContentPane().add(button);
JMenuBar menuBar = new JMenuBar();
menuBar.setBounds(0, 0, 1370, 21);
frmImageViewer.getContentPane().add(menuBar);
JMenu mnNewMenu = new JMenu("File ");
menuBar.add(mnNewMenu);
final JMenuItem item = new JMenuItem(
"Open ");
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
if (panel != null) {
frmImageViewer.getContentPane().remove(panel);
frmImageViewer.repaint();
}
fc = new JFileChooser("");
fc.setDragEnabled(true);
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"JPG & GIF Images", "jpg", "gif");
fc.setFileFilter(filter);
int returnVal = fc.showOpenDialog(item);
if (returnVal == JFileChooser.APPROVE_OPTION) {
file = fc.getSelectedFile();
// System.out.println(23);
ImageFileFilter fileFilter = new ImageFileFilter();
if (fileFilter.accept(file)) {
panel = new Image();
// panel.setBounds(10, 11, 813, 366);
panel.setBounds(0, 0, 1366, 682);
frmImageViewer.getContentPane().add(panel);
frmImageViewer.repaint();
} else {
JOptionPane.showMessageDialog(item,
"File Should be an image");
}
}
}
});
JMenuItem item1 = new JMenuItem("Exit");
item1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
mnNewMenu.add(item);
mnNewMenu.add(item1);
frmImageViewer.setBounds(0, 0, 1366, 728);
frmImageViewer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} catch (Exception e) {
// TODO: handle exception
JOptionPane.showMessageDialog(null, e.getMessage() + e.getClass());
}
}
public void doPri() {
if (panel != null) {
frmImageViewer.getContentPane().remove(panel);
frmImageViewer.repaint();
}
if (file == null) {
fc = new JFileChooser("");
fc.setDragEnabled(true);
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"JPG & GIF Images", "jpg", "gif");
fc.setFileFilter(filter);
int returnVal = fc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
file = fc.getSelectedFile();
ImageFileFilter fileFilter = new ImageFileFilter();
if (fileFilter.accept(file)) {
panel = new Image();
// panel.setBounds(10, 11, 813, 366);
panel.setBounds(0, 0, 1366, 682);
panel.setOpaque(true);
frmImageViewer.getContentPane().add(panel);
frmImageViewer.repaint();
} else {
JOptionPane.showMessageDialog(jPanel1,
"File Should be an image");
}
}
} else {
file = new Dg().priFile(file);
ImageFileFilter fileFilter = new ImageFileFilter();
if (fileFilter.accept(file)) {
panel = new Image();
// panel.setBounds(10, 11, 813, 366);
panel.setBounds(0, 0, 1366, 682);
panel.setOpaque(true);
frmImageViewer.getContentPane().add(panel);
frmImageViewer.repaint();
} else {
JOptionPane.showMessageDialog(jPanel1,
"File Should be an image");
}
}
// System.out.println(23);
}
public void doNext() {
if (panel != null) {
frmImageViewer.getContentPane().remove(panel);
frmImageViewer.repaint();
}
if (file == null) {
fc = new JFileChooser("");
fc.setDragEnabled(true);
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"JPG & GIF Images", "jpg", "gif");
fc.setFileFilter(filter);
int returnVal = fc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
file = fc.getSelectedFile();
ImageFileFilter fileFilter = new ImageFileFilter();
if (fileFilter.accept(file)) {
panel = new Image();
// panel.setBounds(10, 11, 813, 366);
panel.repaint();
panel.setBounds(0, 0, 1366, 682);
frmImageViewer.getContentPane().add(panel);
frmImageViewer.repaint();
} else {
JOptionPane.showMessageDialog(jPanel1,
"File Should be an image");
}
}
} else {
file = new Dg().nextFile(file);
ImageFileFilter fileFilter = new ImageFileFilter();
if (fileFilter.accept(file)) {
panel = new Image();
// panel.setBounds(10, 11, 813, 366);
panel.setBounds(0, 0, 1366, 682);
panel.repaint();
frmImageViewer.getContentPane().add(panel);
frmImageViewer.repaint();
} else {
JOptionPane.showMessageDialog(jPanel1,
"File Should be an image");
}
}
// System.out.println(23);
}
}
// ImageFileFilter.java
import java.io.*;
/**
* A class that implements the Java FileFilter interface.
*/
public class ImageFileFilter implements FileFilter
{
private final String[] okFileExtensions =
new String[] {"jpg", "png", "gif"};
public boolean accept(File file)
{
for (String extension : okFileExtensions)
{
if (file.getName().toLowerCase().endsWith(extension))
{
return true;
}
}
return false;
}
}

More Related Content

Similar to I am sorry but my major does not cover programming in depth (ICT) an.pdf

Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best PracticesYekmer Simsek
 
Oleksandr Tolstykh
Oleksandr TolstykhOleksandr Tolstykh
Oleksandr Tolstykh
CodeFest
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Domenic Denicola
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
udit652068
 
Java Programming Must implement a storage manager that main.pdf
Java Programming Must implement a storage manager that main.pdfJava Programming Must implement a storage manager that main.pdf
Java Programming Must implement a storage manager that main.pdf
adinathassociates
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Remy Sharp
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02PL dream
 
Aiwolf seminar20180630
Aiwolf seminar20180630Aiwolf seminar20180630
Aiwolf seminar20180630
Atom Sonoda
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretssmueller_sandsmedia
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Tsuyoshi Yamamoto
 
Please help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfPlease help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdf
JUSTSTYLISH3B2MOHALI
 
Excelsheet
ExcelsheetExcelsheet
Excelsheet
amarnathprasad
 
Clean Code
Clean CodeClean Code
Clean Code
Nascenia IT
 
More android code puzzles
More android code puzzlesMore android code puzzles
More android code puzzles
Danny Preussler
 
Day 5
Day 5Day 5
Javascript And J Query
Javascript And J QueryJavascript And J Query
Javascript And J Query
itsarsalan
 
Android 3
Android 3Android 3
Android 3
Robert Cooper
 
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
alliedscorporation
 

Similar to I am sorry but my major does not cover programming in depth (ICT) an.pdf (20)

Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 
Oleksandr Tolstykh
Oleksandr TolstykhOleksandr Tolstykh
Oleksandr Tolstykh
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
 
Java Programming Must implement a storage manager that main.pdf
Java Programming Must implement a storage manager that main.pdfJava Programming Must implement a storage manager that main.pdf
Java Programming Must implement a storage manager that main.pdf
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
 
Aiwolf seminar20180630
Aiwolf seminar20180630Aiwolf seminar20180630
Aiwolf seminar20180630
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察
 
Please help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfPlease help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdf
 
Excelsheet
ExcelsheetExcelsheet
Excelsheet
 
Clean Code
Clean CodeClean Code
Clean Code
 
More android code puzzles
More android code puzzlesMore android code puzzles
More android code puzzles
 
Day 5
Day 5Day 5
Day 5
 
Spring hibernate jsf_primefaces_intergration
Spring hibernate jsf_primefaces_intergrationSpring hibernate jsf_primefaces_intergration
Spring hibernate jsf_primefaces_intergration
 
Javascript And J Query
Javascript And J QueryJavascript And J Query
Javascript And J Query
 
Eclipse Tricks
Eclipse TricksEclipse Tricks
Eclipse Tricks
 
Android 3
Android 3Android 3
Android 3
 
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
 

More from seamusschwaabl99557

Note the structures through which light passes to reach the retina. W.pdf
Note the structures through which light passes to reach the retina. W.pdfNote the structures through which light passes to reach the retina. W.pdf
Note the structures through which light passes to reach the retina. W.pdf
seamusschwaabl99557
 
Muriel recently stopped taking her medication resulting in flulike s.pdf
Muriel recently stopped taking her medication resulting in flulike s.pdfMuriel recently stopped taking her medication resulting in flulike s.pdf
Muriel recently stopped taking her medication resulting in flulike s.pdf
seamusschwaabl99557
 
managerial reporting systems areStandardizedRigidFlexible.pdf
managerial reporting systems areStandardizedRigidFlexible.pdfmanagerial reporting systems areStandardizedRigidFlexible.pdf
managerial reporting systems areStandardizedRigidFlexible.pdf
seamusschwaabl99557
 
Lot X_1, ..., X_n be independent and identically distributed continuo.pdf
Lot X_1, ..., X_n be independent and identically distributed continuo.pdfLot X_1, ..., X_n be independent and identically distributed continuo.pdf
Lot X_1, ..., X_n be independent and identically distributed continuo.pdf
seamusschwaabl99557
 
Let Y follows a Poisson distribution with mean lambda that is, Y app.pdf
Let Y follows a Poisson distribution with mean lambda that is, Y app.pdfLet Y follows a Poisson distribution with mean lambda that is, Y app.pdf
Let Y follows a Poisson distribution with mean lambda that is, Y app.pdf
seamusschwaabl99557
 
In humans, the HOXD homeotic gene cluster plays a critical role in l.pdf
In humans, the HOXD homeotic gene cluster plays a critical role in l.pdfIn humans, the HOXD homeotic gene cluster plays a critical role in l.pdf
In humans, the HOXD homeotic gene cluster plays a critical role in l.pdf
seamusschwaabl99557
 
explain why blockage or removal of the lymphatic vessels can result .pdf
explain why blockage or removal of the lymphatic vessels can result .pdfexplain why blockage or removal of the lymphatic vessels can result .pdf
explain why blockage or removal of the lymphatic vessels can result .pdf
seamusschwaabl99557
 
Describe three different symbiotic relationships, with examples. Whi.pdf
Describe three different symbiotic relationships, with examples. Whi.pdfDescribe three different symbiotic relationships, with examples. Whi.pdf
Describe three different symbiotic relationships, with examples. Whi.pdf
seamusschwaabl99557
 
Describe the differences seen in the hydra, planarian, clam, grasshop.pdf
Describe the differences seen in the hydra, planarian, clam, grasshop.pdfDescribe the differences seen in the hydra, planarian, clam, grasshop.pdf
Describe the differences seen in the hydra, planarian, clam, grasshop.pdf
seamusschwaabl99557
 
Companyhas prot s Price per unit Variable cost per unit Fixed costs p.pdf
Companyhas prot s Price per unit Variable cost per unit Fixed costs p.pdfCompanyhas prot s Price per unit Variable cost per unit Fixed costs p.pdf
Companyhas prot s Price per unit Variable cost per unit Fixed costs p.pdf
seamusschwaabl99557
 
Alice Agent is an employee of Patti Principal. She negligently runs .pdf
Alice Agent is an employee of Patti Principal. She negligently runs .pdfAlice Agent is an employee of Patti Principal. She negligently runs .pdf
Alice Agent is an employee of Patti Principal. She negligently runs .pdf
seamusschwaabl99557
 
at log kHz SolutionYou can have several problems 1) if you a.pdf
at log kHz SolutionYou can have several problems 1) if you a.pdfat log kHz SolutionYou can have several problems 1) if you a.pdf
at log kHz SolutionYou can have several problems 1) if you a.pdf
seamusschwaabl99557
 
Bark, which is thicken, toughen periderm, arises from this lateral m.pdf
Bark, which is thicken, toughen periderm, arises from this lateral m.pdfBark, which is thicken, toughen periderm, arises from this lateral m.pdf
Bark, which is thicken, toughen periderm, arises from this lateral m.pdf
seamusschwaabl99557
 
Why do you think it is usually preferable to start with the side con.pdf
Why do you think it is usually preferable to start with the side con.pdfWhy do you think it is usually preferable to start with the side con.pdf
Why do you think it is usually preferable to start with the side con.pdf
seamusschwaabl99557
 
Why is the mucus thicker than normal in CF patients A good answer w.pdf
Why is the mucus thicker than normal in CF patients A good answer w.pdfWhy is the mucus thicker than normal in CF patients A good answer w.pdf
Why is the mucus thicker than normal in CF patients A good answer w.pdf
seamusschwaabl99557
 
Which of the following primordial reproductive structures is NOT ext.pdf
Which of the following primordial reproductive structures is NOT ext.pdfWhich of the following primordial reproductive structures is NOT ext.pdf
Which of the following primordial reproductive structures is NOT ext.pdf
seamusschwaabl99557
 
what kind of accessory protein would you classify IRS1 and 2 as.pdf
what kind of accessory protein would you classify IRS1 and 2 as.pdfwhat kind of accessory protein would you classify IRS1 and 2 as.pdf
what kind of accessory protein would you classify IRS1 and 2 as.pdf
seamusschwaabl99557
 
What is the main difference between prokaryotic and eukaryotic riboso.pdf
What is the main difference between prokaryotic and eukaryotic riboso.pdfWhat is the main difference between prokaryotic and eukaryotic riboso.pdf
What is the main difference between prokaryotic and eukaryotic riboso.pdf
seamusschwaabl99557
 
what is the cardinality of a sample spaceSolutionA sample spa.pdf
what is the cardinality of a sample spaceSolutionA sample spa.pdfwhat is the cardinality of a sample spaceSolutionA sample spa.pdf
what is the cardinality of a sample spaceSolutionA sample spa.pdf
seamusschwaabl99557
 
What is computer information systems in three paragraphs.Solutio.pdf
What is computer information systems in three paragraphs.Solutio.pdfWhat is computer information systems in three paragraphs.Solutio.pdf
What is computer information systems in three paragraphs.Solutio.pdf
seamusschwaabl99557
 

More from seamusschwaabl99557 (20)

Note the structures through which light passes to reach the retina. W.pdf
Note the structures through which light passes to reach the retina. W.pdfNote the structures through which light passes to reach the retina. W.pdf
Note the structures through which light passes to reach the retina. W.pdf
 
Muriel recently stopped taking her medication resulting in flulike s.pdf
Muriel recently stopped taking her medication resulting in flulike s.pdfMuriel recently stopped taking her medication resulting in flulike s.pdf
Muriel recently stopped taking her medication resulting in flulike s.pdf
 
managerial reporting systems areStandardizedRigidFlexible.pdf
managerial reporting systems areStandardizedRigidFlexible.pdfmanagerial reporting systems areStandardizedRigidFlexible.pdf
managerial reporting systems areStandardizedRigidFlexible.pdf
 
Lot X_1, ..., X_n be independent and identically distributed continuo.pdf
Lot X_1, ..., X_n be independent and identically distributed continuo.pdfLot X_1, ..., X_n be independent and identically distributed continuo.pdf
Lot X_1, ..., X_n be independent and identically distributed continuo.pdf
 
Let Y follows a Poisson distribution with mean lambda that is, Y app.pdf
Let Y follows a Poisson distribution with mean lambda that is, Y app.pdfLet Y follows a Poisson distribution with mean lambda that is, Y app.pdf
Let Y follows a Poisson distribution with mean lambda that is, Y app.pdf
 
In humans, the HOXD homeotic gene cluster plays a critical role in l.pdf
In humans, the HOXD homeotic gene cluster plays a critical role in l.pdfIn humans, the HOXD homeotic gene cluster plays a critical role in l.pdf
In humans, the HOXD homeotic gene cluster plays a critical role in l.pdf
 
explain why blockage or removal of the lymphatic vessels can result .pdf
explain why blockage or removal of the lymphatic vessels can result .pdfexplain why blockage or removal of the lymphatic vessels can result .pdf
explain why blockage or removal of the lymphatic vessels can result .pdf
 
Describe three different symbiotic relationships, with examples. Whi.pdf
Describe three different symbiotic relationships, with examples. Whi.pdfDescribe three different symbiotic relationships, with examples. Whi.pdf
Describe three different symbiotic relationships, with examples. Whi.pdf
 
Describe the differences seen in the hydra, planarian, clam, grasshop.pdf
Describe the differences seen in the hydra, planarian, clam, grasshop.pdfDescribe the differences seen in the hydra, planarian, clam, grasshop.pdf
Describe the differences seen in the hydra, planarian, clam, grasshop.pdf
 
Companyhas prot s Price per unit Variable cost per unit Fixed costs p.pdf
Companyhas prot s Price per unit Variable cost per unit Fixed costs p.pdfCompanyhas prot s Price per unit Variable cost per unit Fixed costs p.pdf
Companyhas prot s Price per unit Variable cost per unit Fixed costs p.pdf
 
Alice Agent is an employee of Patti Principal. She negligently runs .pdf
Alice Agent is an employee of Patti Principal. She negligently runs .pdfAlice Agent is an employee of Patti Principal. She negligently runs .pdf
Alice Agent is an employee of Patti Principal. She negligently runs .pdf
 
at log kHz SolutionYou can have several problems 1) if you a.pdf
at log kHz SolutionYou can have several problems 1) if you a.pdfat log kHz SolutionYou can have several problems 1) if you a.pdf
at log kHz SolutionYou can have several problems 1) if you a.pdf
 
Bark, which is thicken, toughen periderm, arises from this lateral m.pdf
Bark, which is thicken, toughen periderm, arises from this lateral m.pdfBark, which is thicken, toughen periderm, arises from this lateral m.pdf
Bark, which is thicken, toughen periderm, arises from this lateral m.pdf
 
Why do you think it is usually preferable to start with the side con.pdf
Why do you think it is usually preferable to start with the side con.pdfWhy do you think it is usually preferable to start with the side con.pdf
Why do you think it is usually preferable to start with the side con.pdf
 
Why is the mucus thicker than normal in CF patients A good answer w.pdf
Why is the mucus thicker than normal in CF patients A good answer w.pdfWhy is the mucus thicker than normal in CF patients A good answer w.pdf
Why is the mucus thicker than normal in CF patients A good answer w.pdf
 
Which of the following primordial reproductive structures is NOT ext.pdf
Which of the following primordial reproductive structures is NOT ext.pdfWhich of the following primordial reproductive structures is NOT ext.pdf
Which of the following primordial reproductive structures is NOT ext.pdf
 
what kind of accessory protein would you classify IRS1 and 2 as.pdf
what kind of accessory protein would you classify IRS1 and 2 as.pdfwhat kind of accessory protein would you classify IRS1 and 2 as.pdf
what kind of accessory protein would you classify IRS1 and 2 as.pdf
 
What is the main difference between prokaryotic and eukaryotic riboso.pdf
What is the main difference between prokaryotic and eukaryotic riboso.pdfWhat is the main difference between prokaryotic and eukaryotic riboso.pdf
What is the main difference between prokaryotic and eukaryotic riboso.pdf
 
what is the cardinality of a sample spaceSolutionA sample spa.pdf
what is the cardinality of a sample spaceSolutionA sample spa.pdfwhat is the cardinality of a sample spaceSolutionA sample spa.pdf
what is the cardinality of a sample spaceSolutionA sample spa.pdf
 
What is computer information systems in three paragraphs.Solutio.pdf
What is computer information systems in three paragraphs.Solutio.pdfWhat is computer information systems in three paragraphs.Solutio.pdf
What is computer information systems in three paragraphs.Solutio.pdf
 

Recently uploaded

Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 

Recently uploaded (20)

Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 

I am sorry but my major does not cover programming in depth (ICT) an.pdf

  • 1. I am sorry but my major does not cover programming in depth (ICT) and we are expected to know advanced java programming. I am looking for help. I have purchased a book from Oracle but I will not be up to speed this semester. Please Help me!!! 1. Write an app called viewer that will have a Label at the top saying "My Viewer" (or something like that) 2. Will have JButtons at the bottom that will do Next, Previous, and Quit 3. Have the whole middle be a JLabel in which you will display Images stored in a directory. 4. The directory can be named Resource. 5. When you run the program (java viewer) it will read all the names in the Resource Directory. Then, when you click Next or Previous it will display an Image. 6. Note: you will need to find a java method that exists for reading a whole directory of filenames. You can store all those names in a String Array when run the program. 7. You will use a counter or index that is an int an when you click Next it will increment the counter until it reach some maximum value and then you will set it to 0. Previous will decrement the counter until it goes negative and then it will set the counter to the Maximum index ( which is how many filenames you have in the Image names array) 8. Submit the program viewer.java I should be able to use it with my own Resource directory Solution Compilation process javac Viewer.java Run java Viewer Click on next or previous a file chooser will be opened and you can select your file The Code is in four file. // File Dg.java import java.io.File; public class Dg { public File nextFile(File file) { File f[] = new File[5000]; f = file.getParentFile().listFiles(new ImageFileFilter()); int max = f.length; max = max - 1;
  • 2. // System.out.println(file); for (int i = 0; i < f.length; i++) { if (f[i].equals(file)) { if (i + 1 > max) { return f[0]; } else { return f[i + 1]; } } else { // System.out.println(0); // return file; } } return file; } public File priFile(File file) { File f[] = new File[5000]; f = file.getParentFile().listFiles(new ImageFileFilter()); int min = 0; // System.out.println(file); for (int i = 0; i < f.length; i++) { if (f[i].equals(file)) { min = i - 1; if (min < 0) { return f[f.length-1]; } else { return f[min]; } } else { // System.out.println(0); // return file; }
  • 3. } return file; } } /// Image.java import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.JPanel; import java.awt.Color; import javax.swing.JLabel; import java.awt.Font; public class Image extends JPanel { /** * */ private static final long serialVersionUID = 1L; public BufferedImage img = null; /** * Create the panel. */ @SuppressWarnings("static-access") public Image() { setBackground(new Color(255, 255, 255)); setLayout(null); try {
  • 4. Viewer ocr = new Viewer(); img = ImageIO.read(ocr.file); JLabel lblNewLabel = new JLabel(Viewer.file.getName()); lblNewLabel.setFont(new Font("Times New Roman", Font.PLAIN, 18)); lblNewLabel.setBounds(10, 25, 268, 24); add(lblNewLabel); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public JPanel getPanel(File file) { JPanel p = new JPanel(); BufferedImage b = null; try { b = ImageIO.read(file); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Graphics g = b.getGraphics(); Graphics2D gd = (Graphics2D) g; gd.drawImage(b, AffineTransform.getScaleInstance(.5, .5), null); return p; } public void paint(Graphics g) { // TODO Auto-generated method stub super.paint(g); // System.out.println("getimage1"); Graphics2D gd = (Graphics2D) g; int h = img.getHeight(); int w = img.getWidth(); int x1 = 0, x2 = 0, x3 = 0, x4 = 0; if (h < 550 && w < 1250) { x1 = (1250 - w) / 2;
  • 5. x2 = (550 - h) / 2; x3 = w; x4 = h; } else if (h < 550 && w >= 1250) { x1 = 20; x2 = (550 - h) / 2; x3 = 1250; x4 = (int) (h * (1250.0 / w)); x2 = (550 - x4) / 2; } else if (h >= 550 && w < 1250) { x1=(1250-w)/2; x2=50; x3=(int) (w*(550.0/h)); x1=(1250-x3)/2; x4=550; } else { x3=(int) (w*(550.0/h)); x4=550; if(x3>1250) { x3=1200; x4 = (int) (h * (1250.0 / x3)); } x1 = (1250 - x3) / 2; x2 = (550 - x4) / 2; x2=50; //.out.println(x2); } // System.out.println(y1);
  • 6. // gd.drawImage(img, AffineTransform.getScaleInstance(x1, x1), null); gd.drawImage(img, x1, x2, x3, x4, null); } } // Viewer.java import java.awt.Color; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.border.LineBorder; import javax.swing.filechooser.FileNameExtensionFilter; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; public class Viewer { private JFrame frmImageViewer; /** * Launch the application. */ JPanel jPanel1 = new JPanel(); JPanel panel = null; static File file = null; JButton openButton, saveButton; JFileChooser fc, fc1;
  • 7. public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @Override public void run() { try { Viewer window = new Viewer(); window.frmImageViewer.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public Viewer() { initialize(); } /** * Initialize the contents of the frame. */ private void initialize() { try { frmImageViewer = new JFrame(); frmImageViewer.setTitle("My Viewer"); // frmImageViewer.getContentPane().setBackground( // new Color(74, 204, 56)); frmImageViewer.getContentPane().setLayout(null); JButton btnNewButton = new JButton("Previous"); btnNewButton.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent arg0) { if (arg0.getExtendedKeyCode() == 37) { doPri(); }
  • 8. if (arg0.getExtendedKeyCode() == 39) { doNext(); } } }); btnNewButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { doPri(); } }); btnNewButton.setBounds(125, 638, 89, 23); frmImageViewer.getContentPane().add(btnNewButton); JButton btnNewButton_1 = new JButton("Next"); btnNewButton_1.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent arg0) { if (arg0.getExtendedKeyCode() == 37) { System.gc(); doPri(); } if (arg0.getExtendedKeyCode() == 39) { System.gc(); doNext(); } } }); btnNewButton_1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { doNext(); System.gc(); } }); btnNewButton_1.setBounds(999, 638, 89, 23); frmImageViewer.getContentPane().add(btnNewButton_1);
  • 9. JButton button = new JButton("close"); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // frmImageViewer.setState(Frame.ICONIFIED); System.exit(0); } }); button.setForeground(new Color(255, 255, 204)); button.setBorder(new LineBorder(new Color(0, 0, 0))); button.setBackground(new Color(204, 0, 51)); button.setBounds(1271, 0, 95, 25); frmImageViewer.getContentPane().add(button); JMenuBar menuBar = new JMenuBar(); menuBar.setBounds(0, 0, 1370, 21); frmImageViewer.getContentPane().add(menuBar); JMenu mnNewMenu = new JMenu("File "); menuBar.add(mnNewMenu); final JMenuItem item = new JMenuItem( "Open "); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (panel != null) { frmImageViewer.getContentPane().remove(panel); frmImageViewer.repaint(); } fc = new JFileChooser(""); fc.setDragEnabled(true); FileNameExtensionFilter filter = new FileNameExtensionFilter( "JPG & GIF Images", "jpg", "gif"); fc.setFileFilter(filter); int returnVal = fc.showOpenDialog(item); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); // System.out.println(23);
  • 10. ImageFileFilter fileFilter = new ImageFileFilter(); if (fileFilter.accept(file)) { panel = new Image(); // panel.setBounds(10, 11, 813, 366); panel.setBounds(0, 0, 1366, 682); frmImageViewer.getContentPane().add(panel); frmImageViewer.repaint(); } else { JOptionPane.showMessageDialog(item, "File Should be an image"); } } } }); JMenuItem item1 = new JMenuItem("Exit"); item1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { System.exit(0); } }); mnNewMenu.add(item); mnNewMenu.add(item1); frmImageViewer.setBounds(0, 0, 1366, 728); frmImageViewer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } catch (Exception e) { // TODO: handle exception JOptionPane.showMessageDialog(null, e.getMessage() + e.getClass()); } } public void doPri() { if (panel != null) { frmImageViewer.getContentPane().remove(panel); frmImageViewer.repaint(); } if (file == null) {
  • 11. fc = new JFileChooser(""); fc.setDragEnabled(true); FileNameExtensionFilter filter = new FileNameExtensionFilter( "JPG & GIF Images", "jpg", "gif"); fc.setFileFilter(filter); int returnVal = fc.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); ImageFileFilter fileFilter = new ImageFileFilter(); if (fileFilter.accept(file)) { panel = new Image(); // panel.setBounds(10, 11, 813, 366); panel.setBounds(0, 0, 1366, 682); panel.setOpaque(true); frmImageViewer.getContentPane().add(panel); frmImageViewer.repaint(); } else { JOptionPane.showMessageDialog(jPanel1, "File Should be an image"); } } } else { file = new Dg().priFile(file); ImageFileFilter fileFilter = new ImageFileFilter(); if (fileFilter.accept(file)) { panel = new Image(); // panel.setBounds(10, 11, 813, 366); panel.setBounds(0, 0, 1366, 682); panel.setOpaque(true); frmImageViewer.getContentPane().add(panel); frmImageViewer.repaint(); } else { JOptionPane.showMessageDialog(jPanel1, "File Should be an image"); } }
  • 12. // System.out.println(23); } public void doNext() { if (panel != null) { frmImageViewer.getContentPane().remove(panel); frmImageViewer.repaint(); } if (file == null) { fc = new JFileChooser(""); fc.setDragEnabled(true); FileNameExtensionFilter filter = new FileNameExtensionFilter( "JPG & GIF Images", "jpg", "gif"); fc.setFileFilter(filter); int returnVal = fc.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); ImageFileFilter fileFilter = new ImageFileFilter(); if (fileFilter.accept(file)) { panel = new Image(); // panel.setBounds(10, 11, 813, 366); panel.repaint(); panel.setBounds(0, 0, 1366, 682); frmImageViewer.getContentPane().add(panel); frmImageViewer.repaint(); } else { JOptionPane.showMessageDialog(jPanel1, "File Should be an image"); } } } else { file = new Dg().nextFile(file); ImageFileFilter fileFilter = new ImageFileFilter(); if (fileFilter.accept(file)) { panel = new Image(); // panel.setBounds(10, 11, 813, 366); panel.setBounds(0, 0, 1366, 682);
  • 13. panel.repaint(); frmImageViewer.getContentPane().add(panel); frmImageViewer.repaint(); } else { JOptionPane.showMessageDialog(jPanel1, "File Should be an image"); } } // System.out.println(23); } } // ImageFileFilter.java import java.io.*; /** * A class that implements the Java FileFilter interface. */ public class ImageFileFilter implements FileFilter { private final String[] okFileExtensions = new String[] {"jpg", "png", "gif"}; public boolean accept(File file) { for (String extension : okFileExtensions) { if (file.getName().toLowerCase().endsWith(extension)) { return true; } } return false; } }