first commit
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
#BlueJ class context
|
||||
comment0.params=
|
||||
comment0.target=ImageViewer()
|
||||
comment0.text=\n\ Create\ an\ ImageViewer\ show\ it\ on\ screen.\n
|
||||
comment1.params=
|
||||
comment1.target=void\ openFile()
|
||||
comment1.text=\n\ Open\ function\:\ open\ a\ file\ chooser\ to\ select\ a\ new\ image\ file.\n
|
||||
comment2.params=
|
||||
comment2.target=void\ quit()
|
||||
comment2.text=\n\ Quit\ function\:\ quit\ the\ application.\n
|
||||
comment3.params=
|
||||
comment3.target=void\ makeFrame()
|
||||
comment3.text=\n\ Create\ the\ Swing\ frame\ and\ its\ content.\n
|
||||
comment4.params=frame
|
||||
comment4.target=void\ makeMenuBar(javax.swing.JFrame)
|
||||
comment4.text=\n\ Create\ the\ main\ frame's\ menu\ bar.\n\ @param\ frame\ \ \ The\ frame\ that\ the\ menu\ bar\ should\ be\ added\ to.\n
|
||||
numComments=5
|
@@ -0,0 +1,87 @@
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* ImageViewer is the main class of the image viewer application. It builds
|
||||
* and displays the application GUI.
|
||||
*
|
||||
* To start the application, create an object of this class.
|
||||
*
|
||||
* @author Michael Kölling and David J. Barnes.
|
||||
* @version 0.3
|
||||
*/
|
||||
public class ImageViewer
|
||||
{
|
||||
private JFrame frame;
|
||||
|
||||
/**
|
||||
* Create an ImageViewer show it on screen.
|
||||
*/
|
||||
public ImageViewer()
|
||||
{
|
||||
makeFrame();
|
||||
}
|
||||
|
||||
|
||||
// ---- implementation of menu functions ----
|
||||
|
||||
/**
|
||||
* Open function: open a file chooser to select a new image file.
|
||||
*/
|
||||
private void openFile()
|
||||
{
|
||||
// this is some test output, until we do this properly
|
||||
System.out.println("open file");
|
||||
}
|
||||
|
||||
/**
|
||||
* Quit function: quit the application.
|
||||
*/
|
||||
private void quit()
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
// ---- swing stuff to build the frame and all its components ----
|
||||
|
||||
/**
|
||||
* Create the Swing frame and its content.
|
||||
*/
|
||||
private void makeFrame()
|
||||
{
|
||||
frame = new JFrame("ImageViewer");
|
||||
makeMenuBar(frame);
|
||||
|
||||
Container contentPane = frame.getContentPane();
|
||||
|
||||
JLabel label = new JLabel("I am a label. I can display some text.");
|
||||
contentPane.add(label);
|
||||
|
||||
// building is done - arrange the components and show
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the main frame's menu bar.
|
||||
* @param frame The frame that the menu bar should be added to.
|
||||
*/
|
||||
private void makeMenuBar(JFrame frame)
|
||||
{
|
||||
JMenuBar menubar = new JMenuBar();
|
||||
frame.setJMenuBar(menubar);
|
||||
|
||||
// create the File menu
|
||||
JMenu fileMenu = new JMenu("File");
|
||||
menubar.add(fileMenu);
|
||||
|
||||
JMenuItem openItem = new JMenuItem("Open");
|
||||
openItem.addActionListener(e -> openFile());
|
||||
fileMenu.add(openItem);
|
||||
|
||||
JMenuItem quitItem = new JMenuItem("Quit");
|
||||
quitItem.addActionListener(e -> quit());
|
||||
fileMenu.add(quitItem);
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
Project: imageviewer, version 0.3
|
||||
Authors: David Barnes and Michael Kölling
|
||||
|
||||
This project is part of the material for the book
|
||||
|
||||
Objects First with Java - A Practical Introduction using BlueJ
|
||||
Sixth edition
|
||||
David J. Barnes and Michael Kölling
|
||||
Pearson Education, 2016
|
||||
|
||||
It is discussed in chapter 13.
|
||||
|
||||
To use this project, create an instance of class ImageViewer.
|
||||
For details, refer to the book chapter.
|
@@ -0,0 +1,29 @@
|
||||
#BlueJ package file
|
||||
objectbench.height=76
|
||||
objectbench.width=679
|
||||
package.editor.height=369
|
||||
package.editor.width=571
|
||||
package.editor.x=70
|
||||
package.editor.y=80
|
||||
package.numDependencies=0
|
||||
package.numTargets=1
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=UTF-8
|
||||
readme.editor.height=534
|
||||
readme.editor.width=776
|
||||
readme.editor.x=53
|
||||
readme.editor.y=23
|
||||
target1.editor.height=736
|
||||
target1.editor.width=938
|
||||
target1.editor.x=231
|
||||
target1.editor.y=58
|
||||
target1.height=60
|
||||
target1.name=ImageViewer
|
||||
target1.naviview.expanded=true
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.typeParameters=
|
||||
target1.width=120
|
||||
target1.x=210
|
||||
target1.y=130
|
Reference in New Issue
Block a user