ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 2 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 04 May 2017 My Price 13.00

CSC 143 Assignment #2 Testing Benford’s Law

Hello, I have this CSC assignment. I have attached 3 files of one assignment.

CSC 143 Assignment #2
Testing Benford’s Law
For 25 points
Due Date: see Canvas class site
The Case Study described in Section 7.6 of our text book describes Benford’s Law:
Benford’s Law involves looking at the first digit of a series of numbers. For
example, suppose that you were to use a random number generator to generate
integers in the range of 100 to 999 and you looked at how often the number
begins with 1, how often it begins with 2, and so on. Any decent random number
generator would spread the answers out evenly among the 9 regions, so we’d
expect to see each digit about one-ninth of the time (11.1%). But with a lot of
real-world data, we see a very different distribution.
Table 7.3 gives the expected distribution under Benford’s Law:
1: 30.1%, 2: 17.6%, 3: 12.5%, 4: 9.7%, 5: 7.9%, 6: 6.7%, 7: 5.8%, 8: 5.1%, 9: 4.6%
You should use this distribution in your program.
You are being provided with a text file giving population data for 247 countries and territories.
Your program should read in the data in this file and extract the information needed to keep
count of how often each first digit is found. It may be useful to know that the ASCII value for the
character ‘1’ is 49.
In addition, you should analyze other publicly available data to see how they test for Benford
analysis. One data repository site where you can find multiple datasets is:
https://archive.ics.uci.edu/ml/datasets.html
For this assignment, you are to design a Java class named Benford that uses an ArrayList object
to store counts of first digits. A Benford object will have only one field, the ArrayList object.
You will need the following class methods (at a minimum – you may add as many helper
methods as you wish): A constructor to construct Benford objects
A class method named readCounts() that takes a file name as a parameter and that reads
and stores data from a text file into a Benford object.
A class method named benfordPercents() that uses the data in the Benford object to fill
an array of double values giving the percentage counts for each initial digit based on the
raw counts contained in the Benford object. You are also to design a client class named BenfordPlot that displays the data in the Benford
object graphically. The output should be similar to the examples shown below, except your plot
should be titled “Population of Countries.” The “^” symbol in the plot below indicated the
expected Benford value. The second plot shown below displays a distribution that does NOT
follow Benford’s Law. The file containing the data you need for this assignment is “popData.txt” – it was obtained from
the website http://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population
A sample of the data file you will be working with is shown below, so that you can see the
format of the data you’ll be using: The fact that only the population data is numerical may help you parse the data file. Plot the
population data provided to determine whether or not it follows Benford’s Law.
The DrawingPanel.java code is also being provided, in case you do not already have it
downloaded.
Please submit the following files: Benford.java (your Benford class code) - one per team.
BenfordPlot.java (your client code that using the DrawingPanel code to produce a
graphical display of the data contained in a Benford object) – one per team
Analysis of multiple data sets along with your opinion as to whether or not the data
follow Benford’s Law – one per person Design and implementation guidelines: Javadoc comment all class files and methods
Use validation and generate and handle exceptions as appropriate
Structured code - use methods to eliminate redundancy and break large methods into
smaller, logical subproblems

 

/**
The DrawingPanel class provides a simple interface for drawing persistent
images using a Graphics object. An internal BufferedImage object is used
to keep track of what has been drawn. A client of the class simply
constructs a DrawingPanel of a particular size and then draws on it with
the Graphics object, setting the background color if they so choose.
<p>
To ensure that the image is always displayed, a timer calls repaint at
regular intervals.
<p>
This version of DrawingPanel also saves animated GIFs, though this is kind
of hit-and-miss because animated GIFs are pretty sucky (256 color limit, large
file size, etc).
<p>
Recent features:
- save zoomed images (2011/10/25)
- window no longer moves when zoom changes (2011/10/25)
- grid lines (2011/10/11)
@author Marty Stepp
@version October 21, 2011
*/
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import java.awt.AlphaComposite;
java.awt.BorderLayout;
java.awt.Color;
java.awt.Composite;
java.awt.Container;
java.awt.Dimension;
java.awt.EventQueue;
java.awt.FlowLayout;
java.awt.Font;
java.awt.Frame;
java.awt.Graphics;
java.awt.Graphics2D;
java.awt.GridLayout;
java.awt.Image;
java.awt.Point;
java.awt.RenderingHints;
java.awt.Toolkit;
java.awt.Window;
java.awt.event.ActionEvent;
java.awt.event.ActionListener;
java.awt.event.KeyEvent;
java.awt.event.KeyListener;
java.awt.event.MouseEvent;
java.awt.event.MouseListener;
java.awt.event.MouseMotionListener;
java.awt.event.WindowEvent;
java.awt.event.WindowListener;
java.awt.image.BufferedImage;
java.awt.image.PixelGrabber;
java.io.File;
java.io.FileOutputStream;
java.io.IOException;
java.io.OutputStream;
java.io.PrintStream;
java.lang.Exception;
java.lang.Integer;
java.lang.InterruptedException;
java.lang.Math; import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import java.lang.Object;
java.lang.OutOfMemoryError;
java.lang.SecurityException;
java.lang.String;
java.lang.System;
java.lang.Thread;
java.net.URL;
java.net.NoRouteToHostException;
java.net.SocketException;
java.net.UnknownHostException;
java.util.ArrayList;
java.util.List;
java.util.Scanner;
java.util.Vector;
javax.imageio.ImageIO;
javax.swing.BorderFactory;
javax.swing.Box;
javax.swing.JButton;
javax.swing.JCheckBox;
javax.swing.JCheckBoxMenuItem;
javax.swing.JColorChooser;
javax.swing.JDialog;
javax.swing.JFileChooser;
javax.swing.JFrame;
javax.swing.JLabel;
javax.swing.JMenu;
javax.swing.JMenuBar;
javax.swing.JMenuItem;
javax.swing.JOptionPane;
javax.swing.JPanel;
javax.swing.JScrollPane;
javax.swing.JSlider;
javax.swing.KeyStroke;
javax.swing.SwingConstants;
javax.swing.Timer;
javax.swing.UIManager;
javax.swing.event.ChangeEvent;
javax.swing.event.ChangeListener;
javax.swing.event.MouseInputListener;
javax.swing.filechooser.FileFilter; public final class DrawingPanel extends FileFilter
implements ActionListener, MouseMotionListener, Runnable, WindowListener {
// inner class to represent one frame of an animated GIF
private static class ImageFrame {
public Image image;
public int delay;
public ImageFrame(Image image, int delay) {
this.image = image;
this.delay = delay / 10;
// strangely, gif stores delay as sec/100
}
}
// class constants
public static final String ANIMATED_PROPERTY
= "drawingpanel.animated";
public static final String AUTO_ENABLE_ANIMATION_ON_SLEEP_PROPERTY =
"drawingpanel.animateonsleep";
public static final String DIFF_PROPERTY
= "drawingpanel.diff";
public static final String HEADLESS_PROPERTY
= "drawingpanel.headless";
public static final String MULTIPLE_PROPERTY
= "drawingpanel.multiple";
public static final String SAVE_PROPERTY
= "drawingpanel.save";
public static final String ANIMATION_FILE_NAME =
"_drawingpanel_animation_save.txt"; private static final String TITLE
= "Drawing Panel";
private static final String COURSE_WEB_SITE =
"http://www.cs.washington.edu/education/courses/cse142/12sp/drawingpanel.txt";
private static final Color GRID_LINE_COLOR
= new Color(64, 64, 64, 128);
private static final int GRID_SIZE
= 10;
// 10px between
grid lines
private static final int DELAY
= 100;
// delay between
repaints in millis
private static final int MAX_FRAMES
= 100;
// max animation
frames
private static final int MAX_SIZE
= 10000;
// max
width/height
private static final boolean DEBUG
= false;
private static final boolean SAVE_SCALED_IMAGES = true;
// if true, when
panel is zoomed, saves images at that zoom factor
private static int instances = 0;
private static Thread shutdownThread = null;
private static void checkAnimationSettings() {
try {
File settingsFile = new File(ANIMATION_FILE_NAME);
if (settingsFile.exists()) {
Scanner input = new Scanner(settingsFile);
String animationSaveFileName = input.nextLine();
input.close();
// *** TODO: delete the file
System.out.println("***");
System.out.println("*** DrawingPanel saving animated GIF: " +
new File(animationSaveFileName).getName());
System.out.println("***");
settingsFile.delete();
System.setProperty(ANIMATED_PROPERTY, "1");
System.setProperty(SAVE_PROPERTY, animationSaveFileName);
}
} catch (Exception e) {
if (DEBUG) {
System.out.println("error checking animation settings: " + e);
}
}
}
private static boolean hasProperty(String name) {
try {
return System.getProperty(name) != null;
} catch (SecurityException e) {
if (DEBUG) System.out.println("Security exception when trying to
read " + name);
return false;
}
}
private static boolean propertyIsTrue(String name) {
try {
String prop = System.getProperty(name);
return prop != null && (prop.equalsIgnoreCase("true") ||
prop.equalsIgnoreCase("yes") || prop.equalsIgnoreCase("1"));
} catch (SecurityException e) {
if (DEBUG) System.out.println("Security exception when trying to
read " + name);
return false;
}
} /*
private static boolean propertyIsFalse(String name) {
try {
String prop = System.getProperty(name);
return prop != null && (prop.equalsIgnoreCase("false") ||
prop.equalsIgnoreCase("no") || prop.equalsIgnoreCase("0"));
} catch (SecurityException e) {
if (DEBUG) System.out.println("Security exception when trying to
read " + name);
return false;
}
}
*/
// Returns whether the 'main' thread is still running.
private static boolean mainIsActive() {
ThreadGroup group = Thread.currentThread().getThreadGroup();
int activeCount = group.activeCount();
// look for the main thread in the current thread group
Thread threads = new Thread[activeCount];
group.enumerate(threads);
for (int i = 0; i < threads.length; i++) {
Thread thread = threads[i];
String name = ("" + thread.getName()).toLowerCase();
if (name.indexOf("main") >= 0 ||
name.indexOf("testrunner-assignmentrunner") >= 0) {
// found main thread!
// (TestRunnerApplet's main runner also counts as "main" thread)
return thread.isAlive();
}
} } // didn't find a running main thread; guess that main is done running
return false; private static boolean usingDrJava() {
try {
return System.getProperty("drjava.debug.port") != null ||
System.getProperty("java.class.path").toLowerCase().indexOf("drjava") >= 0;
} catch (SecurityException e) {
// running as an applet, or something
return false;
}
}
private class ImagePanel extends JPanel {
private static final long serialVersionUID = 0;
private Image image;
public ImagePanel(Image image) {
setImage(image);
setBackground(Color.WHITE);
setPreferredSize(new Dimension(image.getWidth(this),
image.getHeight(this)));
setAlignmentX(0.0f);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
if (currentZoom != 1) { g2.scale(currentZoom, currentZoom);
}
g2.drawImage(image, 0, 0, this); GRID_SIZE); // possibly draw grid lines for debugging
if (gridLines) {
g2.setPaint(GRID_LINE_COLOR);
for (int row = 1; row <= getHeight() / GRID_SIZE; row++) {
g2.drawLine(0, row * GRID_SIZE, getWidth(), row * getHeight());
} }
for (int col = 1; col <= getWidth() / GRID_SIZE; col++) {
g2.drawLine(col * GRID_SIZE, 0, col * GRID_SIZE,
} }
public void setImage(Image image) {
this.image = image;
repaint();
}
}
// fields
private int width, height;
// dimensions of window frame
private JFrame frame;
// overall window frame
private JPanel panel;
// overall drawing surface
private ImagePanel imagePanel;
// real drawing surface
private BufferedImage image;
// remembers drawing commands
private Graphics2D g2;
// graphics context for painting
private JLabel statusBar;
// status bar showing mouse position
private JFileChooser chooser;
// file chooser to save files
private long createTime;
// time at which DrawingPanel was
constructed
private Timer timer;
// animation timer
private ArrayList<ImageFrame> frames; // stores frames of animation to save
private Gif89Encoder encoder;
// private FileOutputStream stream;
private Color backgroundColor = Color.WHITE;
private String callingClassName;
// name of class that constructed
this panel
private boolean animated = false;
// changes to true if sleep() is
called
private boolean PRETTY = true;
// true to anti-alias
private boolean gridLines = false;
private int instanceNumber;
private int currentZoom = 1;
private int initialPixel;
// initial value in each pixel, for
clear()
// construct a drawing panel of given width and height enclosed in a window
public DrawingPanel(int width, int height) {
if (width < 0 || width > MAX_SIZE || height < 0 || height > MAX_SIZE) {
throw new IllegalArgumentException("Illegal width/height: " + width
+ " x " + height);
}
checkAnimationSettings(); number synchronized (getClass()) {
instances++;
instanceNumber = instances; // each DrawingPanel stores its own int if (shutdownThread == null && !usingDrJava()) {
shutdownThread = new Thread(new Runnable() {
// Runnable implementation; used for shutdown thread.
public void run() {
try {
while (true) {
// maybe shut down the program, if no more
DrawingPanels are onscreen
// and main has finished executing
if ((instances == 0 || shouldSave()) && !
mainIsActive()) {
try {
System.exit(0);
} catch (SecurityException sex) {}
}
Thread.sleep(250);
}
} catch (Exception e) {}
}
});
shutdownThread.setPriority(Thread.MIN_PRIORITY);
shutdownThread.start();
}
}
this.width = width;
this.height = height;
if (DEBUG) System.out.println("w=" + width + ",h=" + height + ",anim=" +
isAnimated() + ",graph=" + isGraphical() + ",save=" + shouldSave());
if (isAnimated() && shouldSave()) {
// image must be no more than 256 colors
image = new BufferedImage(width, height,
BufferedImage.TYPE_BYTE_INDEXED);
// image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);
PRETTY = false;
// turn off anti-aliasing to save palette colors
// initially fill the entire frame with the background color,
// because it won't show through via transparency like with a full
ARGB image Graphics g = image.getGraphics();
g.setColor(backgroundColor);
g.fillRect(0, 0, width + 1, height + 1);
} else {
image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);
}
initialPixel = image.getRGB(0, 0);
g2 = (Graphics2D) image.getGraphics();
g2.setColor(Color.BLACK);
if (PRETTY) {
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
}
if (isAnimated()) {
initializeAnimation();
}
if (isGraphical()) { try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {}
statusBar = new JLabel(" ");
statusBar.setBorder(BorderFactory.createLineBorder(Color.BLACK));
panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
panel.setBackground(backgroundColor);
panel.setPreferredSize(new Dimension(width, height));
imagePanel = new ImagePanel(image);
imagePanel.setBackground(backgroundColor);
panel.add(imagePanel);
// listen to mouse movement
panel.addMouseMotionListener(this);
// main window frame
frame = new JFrame(TITLE);
// frame.setResizable(false);
frame.addWindowListener(this);
// JPanel center = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0)); JScrollPane center = new JScrollPane(panel);
// center.add(panel);
frame.getContentPane().add(center);
frame.getContentPane().add(statusBar, "South");
frame.setBackground(Color.DARK_GRAY);
// menu bar
setupMenuBar();
frame.pack();
center(frame);
frame.setVisible(true);
if (!shouldSave()) {
toFront(frame);
}
// repaint timer so that the screen will update
createTime = System.currentTimeMillis();
timer = new Timer(DELAY, this);
timer.start();
} else if (shouldSave()) {
// headless mode; just set a hook on shutdown to save the image
callingClassName = getCallingClassName();
try {
Runtime.getRuntime().addShutdownHook(new Thread(this));
} catch (Exception e) {
if (DEBUG) System.out.println("unable to add shutdown hook: " + e); } } }
// method of FileFilter interface
public boolean accept(File file) {
return file.isDirectory() ||
(file.getName().toLowerCase().endsWith(".png") ||
file.getName().toLowerCase().endsWith(".gif"));
}
// used for an internal timer that keeps repainting public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof Timer) {
// redraw the screen at regular intervals to catch all paint
operations
panel.repaint();
if (shouldDiff() &&
System.currentTimeMillis() > createTime + 4 * DELAY) {
String expected = System.getProperty(DIFF_PROPERTY);
try {
String actual = saveToTempFile();
DiffImage diff = new DiffImage(expected, actual);
diff.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} catch (IOException ioe) {
System.err.println("Error diffing image: " + ioe);
}
timer.stop();
} else if (shouldSave() && readyToClose()) {
// auto-save-and-close if desired
try {
if (isAnimated()) {
saveAnimated(System.getProperty(SAVE_PROPERTY));
} else {
save(System.getProperty(SAVE_PROPERTY));
}
} catch (IOException ioe) {
System.err.println("Error saving image: " + ioe);
}
exit();
}
} else if (e.getActionCommand().equals("Exit")) {
exit();
} else if (e.getActionCommand().equals("Compare to File...")) {
compareToFile();
} else if (e.getActionCommand().equals("Compare to Web File...")) {
new Thread(new Runnable() {
public void run() {
compareToURL();
}
}).start();
} else if (e.getActionCommand().equals("Save As...")) {
saveAs();
} else if (e.getActionCommand().equals("Save Animated GIF...")) {
saveAsAnimated();
} else if (e.getActionCommand().equals("Zoom In")) {
zoom(currentZoom + 1);
} else if (e.getActionCommand().equals("Zoom Out")) {
zoom(currentZoom - 1);
} else if (e.getActionCommand().equals("Zoom Normal (100%)")) {
zoom(1);
} else if (e.getActionCommand().equals("Grid Lines")) {
setGridLines(((JCheckBoxMenuItem) e.getSource()).isSelected());
} else if (e.getActionCommand().equals("About...")) {
JOptionPane.showMessageDialog(frame,
"DrawingPanel\n" +
"Graphical library class to support Building Java Programs
textbook\n" +
"written by Marty Stepp and Stuart Reges\n" +
"University of Washington\n\n" +
"please visit our web site at:\n" +
"http://www.buildingjavaprograms.com/", } "About DrawingPanel",
JOptionPane.INFORMATION_MESSAGE); }
public void addKeyListener(KeyListener listener) {
frame.addKeyListener(listener);
}
public void addMouseListener(MouseListener listener) {
panel.addMouseListener(listener);
}
public void addMouseListener(MouseMotionListener listener) {
panel.addMouseMotionListener(listener);
}
public void addMouseMotionListener(MouseMotionListener listener) {
panel.addMouseMotionListener(listener);
}
public void addMouseListener(MouseInputListener listener) {
panel.addMouseListener(listener);
panel.addMouseMotionListener(listener);
}
// erases all drawn shapes/lines/colors from the panel
public void clear() {
int pixels = new int[width * height];
for (int i = 0; i < pixels.length; i++) {
pixels[i] = initialPixel;
}
image.setRGB(0, 0, width, height, pixels, 0, 1);
}
// erases all drawn shapes/lines/colors from the panel
public void clearWithoutRepaint() {
Graphics g = image.getGraphics();
g.setColor(backgroundColor);
g.fillRect(0, 0, getWidth(), getHeight());
}
// method of FileFilter interface
public String getDescription() {
return "Image files (*.png; *.gif)";
}
// obtain the Graphics object to draw on the panel
public Graphics2D getGraphics() {
return g2;
}
// returns the drawing panel's width in pixels
public int getHeight() {
return height;
}
// returns the drawing panel's pixel size (width, height) as a Dimension
object
public Dimension getSize() {
return new Dimension(width, height);
}
// returns the drawing panel's width in pixels
public int getWidth() {
return width;
} // returns panel's current zoom factor
public int getZoom() {
return currentZoom;
}
// listens to mouse dragging
public void mouseDragged(MouseEvent e) {}
// listens to mouse movement
public void mouseMoved(MouseEvent e) {
int x = e.getX() / currentZoom;
int y = e.getY() / currentZoom;
setStatusBarText("(" + x + ", " + y + ")");
}
// run on shutdown to save the image
public void run() {
if (DEBUG) System.out.println("Running shutdown hook");
try {
String filename = System.getProperty(SAVE_PROPERTY);
if (filename == null) {
filename = callingClassName + ".png";
}
if (isAnimated()) {
saveAnimated(filename);
} else {
save(filename);
}
} catch (SecurityException e) {
} catch (IOException e) {
System.err.println("Error saving image: " + e);
}
}
// take the current contents of the panel and write them to a file
public void save(String filename) throws IOException {
BufferedImage image2 = getImage();
// if zoomed, scale image before saving it
if (SAVE_SCALED_IMAGES && currentZoom != 1) {
BufferedImage zoomedImage = new BufferedImage(width * currentZoom,
height * currentZoom, image.getType());
Graphics2D g = (Graphics2D) zoomedImage.getGraphics();
g.setColor(Color.BLACK);
if (PRETTY) {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
}
g.scale(currentZoom, currentZoom);
g.drawImage(image2, 0, 0, imagePanel);
image2 = zoomedImage;
}
// if saving multiple panels, append number
// (e.g. output_*.png becomes output_1.png, output_2.png, etc.)
if (isMultiple()) {
filename = filename.replaceAll("\\*",
String.valueOf(instanceNumber));
}
int lastDot = filename.lastIndexOf(".");
String extension = filename.substring(lastDot + 1); // write file
// TODO: doesn't save background color I don't think
ImageIO.write(image2, extension, new File(filename));
}
// take the current contents of the panel and write them to a file
public void saveAnimated(String filename) throws IOException {
// add one more final frame
if (DEBUG) System.out.println("saveAnimated(" + filename + ")");
frames.add(new ImageFrame(getImage(), 5000));
// encoder.continueEncoding(stream, getImage(), 5000);
// Gif89Encoder gifenc = new Gif89Encoder();
// add each frame of animation to the encoder
try {
for (int i = 0; i < frames.size(); i++) {
ImageFrame imageFrame = frames.get(i);
encoder.addFrame(imageFrame.image);
encoder.getFrameAt(i).setDelay(imageFrame.delay);
imageFrame.image.flush();
frames.set(i, null);
}
} catch (OutOfMemoryError e) {
System.out.println("Out of memory when saving");
}
// gifenc.setComments(annotation);
// gifenc.setUniformDelay((int) Math.round(100 / frames_per_second));
// gifenc.setUniformDelay(DELAY);
// encoder.setBackground(backgroundColor);
encoder.setLoopCount(0);
encoder.encode(new FileOutputStream(filename));
}
// set the background color of the drawing panel
public void setBackground(Color c) {
Color oldBackgroundColor = backgroundColor;
backgroundColor = c;
if (isGraphical()) {
panel.setBackground(c);
imagePanel.setBackground(c);
}
// with animated images, need to palette-swap the old bg color for the
new } // because there's no notion of transparency in a palettized 8-bit image
if (isAnimated()) {
replaceColor(image, oldBackgroundColor, c);
} // Enables or disables the drawing of grid lines on top of the image to help
// with debugging sizes and coordinates.
public void setGridLines(boolean gridLines) {
this.gridLines = gridLines;
imagePanel.repaint();
}
// sets the drawing panel's height in pixels to the given value
// After calling this method, the client must call getGraphics() again
// to get the new graphics context of the newly enlarged image buffer.
public void setHeight(int height) { } setSize(getWidth(), height); // sets the drawing panel's pixel size (width, height) to the given values
// After calling this method, the client must call getGraphics() again
// to get the new graphics context of the newly enlarged image buffer.
public void setSize(int width, int height) {
// replace the image buffer for drawing
BufferedImage newImage = new BufferedImage(width, height,
image.getType());
imagePanel.setImage(newImage);
newImage.getGraphics().drawImage(image, 0, 0, imagePanel);
this.width = width;
this.height = height;
image = newImage;
g2 = (Graphics2D) newImage.getGraphics();
g2.setColor(Color.BLACK);
if (PRETTY) {
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
}
zoom(currentZoom);
if (isGraphical()) {
frame.pack();
}
}
// show or hide the drawing panel on the screen
public void setVisible(boolean visible) {
if (isGraphical()) {
frame.setVisible(visible);
}
}
// sets the drawing panel's width in pixels to the given value
// After calling this method, the client must call getGraphics() again
// to get the new graphics context of the newly enlarged image buffer.
public void setWidth(int width) {
setSize(width, getHeight());
}
// makes the program pause for the given amount of time,
// allowing for animation
public void sleep(int millis) {
if (isGraphical() && frame.isVisible()) {
// if not even displaying, we don't actually need to sleep
if (millis > 0) {
try {
Thread.sleep(millis);
panel.repaint();
toFront(frame);
} catch (Exception e) {}
}
}
// manually enable animation if necessary
if (!isAnimated() && !isMultiple() && autoEnableAnimationOnSleep()) {
animated = true;
initializeAnimation();
}
// capture a frame of animation
if (isAnimated() && shouldSave() && !isMultiple()) { try {
if (frames.size() < MAX_FRAMES) {
frames.add(new ImageFrame(getImage(), millis));
}
// reset creation timer so that we won't save/close just yet
createTime = System.currentTimeMillis();
} catch (OutOfMemoryError e) {
System.out.println("Out of memory after capturing " +
frames.size() + " frames");
}
}
}
// moves window on top of other windows
public void toFront() {
toFront(frame);
}
// called when DrawingPanel closes, to potentially exit the program
public void windowClosing(WindowEvent event) {
frame.setVisible(false);
synchronized (getClass()) {
instances--;
}
frame.dispose();
}
// methods required by WindowListener interface
public void windowActivated(WindowEvent event) {}
public void windowClosed(WindowEvent event) {}
public void windowDeactivated(WindowEvent event) {}
public void windowDeiconified(WindowEvent event) {}
public void windowIconified(WindowEvent event) {}
public void windowOpened(WindowEvent event) {}
// zooms the drawing panel in/out to the given factor
// factor should be >= 1
public void zoom(int zoomFactor) {
currentZoom = Math.max(1, zoomFactor);
if (isGraphical()) {
Dimension size = new Dimension(width * currentZoom, height *
currentZoom);
imagePanel.setPreferredSize(size);
panel.setPreferredSize(size);
imagePanel.validate();
imagePanel.revalidate();
panel.validate();
panel.revalidate();
// imagePanel.setSize(size);
frame.getContentPane().validate();
imagePanel.repaint();
setStatusBarText(" ");
size // resize frame if any more space for it exists or it's the wrong
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
if (size.width <= screen.width || size.height <= screen.height) {
frame.pack();
}
// if (size.width <= screen.width && size.height <= screen.height) {
//
frame.pack();
//
center(frame); } // } }
// moves given jframe to center of screen
private void center(Window frame) {
Toolkit tk = Toolkit.getDefaultT...

China 1369480000 India 1270250000 United 320865000 Indonesia 255461700 Brazil 204215000 Pakistan 189607000 Nigeria 183523000 Bangladesh 158223000 Russia 146267288 Japan 126910000 Mexico 121005815 Philippines 101345800 Vietnam 91583000 Ethiopia 90076012 Egypt 88404300 Germany 81083600 Iran 78287900 Turkey 77695904 Democratic Republic of the Congo 71246000 France 66121000 Thailand 65104000 United Kingdon 64800000 Italy 60788845 South Africa 54002000 Burma 51419420 South Korea 51342881 Colombia 48098100 Tanzania 47421786 Kenya 46749000 Spain 46464053 Argentina 43131966 Ukraine 42895704 Algeria 39500000 Poland 38484000 Sudan 38435252 Iraq 36004552 Canada 35702707 Uganda 34856813 Morocco 33848242 Saudi Arabia 31521418 Peru 31151643 Venezuela 30620404 Malaysia 30562200 Uzbekistan 30492800 Nepal 28037904 Ghana 27043093 Afghanistan 26556800 Yemen 25956000 Mozambique 25727911 North Korea 25155000 Angola 24383301 Australia 23821900 Taiwan 23449287 Syria 23163313 Ivory Coast 22671331 Madagascar 21842167 Cameroon 21143237 Sri Lanka 20675000 Romania 19942642 Niger 19268000 Burkina Faso 18450494 Chile 18006407 Kazakhstan 17458500 Netherlands 16899600 Malawi 16310431 Mali 16259000 Guatemala 15806675 Zambia 15473905 Ecuador 15466000 Cambodia 15405157 Chad 13606000 Senegal 13508715 Zimbabwe 13061239 South Sudan 11892934 Bolivia 11410651 Belgium 11239755 Cuba 11210064 Somalia 11123000 Rwanda 10996891 Greece 10992589 Tunisia 10982754 Haiti 10911819 Guinea 10628972 Czech Republic 10538275 Portugal 10477800 Dominican Republic 10378267 Benin 10315244 Hungary 9849000 Burundi 9823827 Sweden 9760142 Azerbaijan 9611700 United Arab Emirates 9577000 Belarus 9481000 Honduras 8725111 Austria 8579747 Tajikistan 8354000 Israel 8345000 Switzerland 8211700 Papua New Guinea 7398500 Hong Kong 7264100 Bulgaria 7202198 Togo 7171000 Serbia 7146759 Paraguay 7003406 Laos 6802000 Eritrea 6738000 Jordan 6721780 El Salvador 6401240 Sierra Leone 6319000 Libya 6317000 Nicaragua 6134270 Kyrgyzstan 5915300 Denmark 5659715 Finland 5478002 Singapore 5469700 Slovakia 5421349 Norway 5165802 Central African Republic 4803000 Costa Rica 4773130 Turkmenistan 4751120 Palestine 4682467 Republic of the Congo 4671000 Ireland 4609600 New Zealand 4577530 Liberia 4503000 Georgia 4490500 Croatia 4267558 Oman 4161705 Lebanon 4104000 Bosnia and Herzegovina 3791622 Panama 3764166 Mauritania 3631775 Moldova 3555200 Puerto Rico 3548397 Uruguay 3404189 Kuwait 3268431 Mongolia 3015207 Armenia 3013900 Lithuania 2916443 Albania 2893005 Jamaica 2717991 Qatar 2334029 Namibia 2280700 Lesotho 2120000 Slovenia 2066407 Macedonia 2065769 Botswana 2056000 Latvia 1985600 The Gambia 1882450 Kosovo 1827231 Guinea-Bissau 1788000 Gabon 1751000 Equatorial Guinea 1430000 Trinidad and Tobago 1328019 Bahrain 1316500 Estonia 1312252 Mauritius 1261208 East Timor 1212107 Swaziland 1119375 Djibouti 900000 Fiji 859178 Cyprus 858000 Reunion 844994 Comoros 763952 Bhutan 759740 Guyana 746900 Macau 636200 Montenegro 620029 Solomon Islands 581344 Luxembourg 562958 Suriname 534189 Cape Verde 518467 Western Sahara 510713 Transnistria 505153 Malta 425384 Guadeloupe 405739 Brunei 393372 Martinique 381326 The Bahamas 368390 Belize 358899 Maldives 341256 Iceland 329100 Northern Cyprus 294906 Barbados 285000 New Caledonia 268767 French Polynesia 268270 Vanuatu 264652 Abkhazia 240705 French Guiana 239648 Mayotte 212645 Samoa 187820 Sao Tome and Principe 187356 Saint Lucia 185000 Guam 159358 Curacao 154843 Saint Vincent and the Grenadines 109000 Aruba 107394 Kiribati 106461 United States Virgin Islands 106405 Grenada 103328 Tonga 103252 Federated States of Micronesia 101351 Jersey 99000 Seychelles 89949 Antigua and Barbuda 86295 Isle Of Man 84497 Andorra 76949 Dominica 71293 Bermuda 64237 Guernsey 65150 Marshall Islands 56086 Greenland 55984 Cayman Islands 55691 American Samoa 55519 Saint Kitts and Nevis 55000 Northern Mariana Islands 53883 South Ossetia 51547 Faroe Islands 48724 Sint Maarten 37429 Liechtenstein 37370 Monaco 36950 Collectivity of Saint Martin 35742 San Marino 32789 Turks and Caicos Islands 31458 Gibraltar 30001 Aland Islands 28875 British Virgin Islands 28054 Caribbean Netherlands 23296 Palau 20901 Cook Islands 14974 Anguilla 13452 Wallis and Futuna 13135 Tuvalu 11323 Nauru 10084 Saint Barthelemy 9131 Saint Pierre and Miquelon 6069 Montserrat 4922 "Saint Helens, Ascension and Tristan da Cunha" 4000 Falkland Islands 3000 Svalbard and Jan Mayen 2562 Norfolk Island 2302 Christmas Island 2072 Niue 1613 Tokelau 1411 Vatican City 839 Cocos (Keeling) Islands 550 Pitcairn Islands 56

Attachments:

Answers

(11)
Status NEW Posted 04 May 2017 12:05 AM My Price 13.00

-----------

Not Rated(0)