I have to make an application called miles to meters that converts miles to meters that asks for user input through joption pane and the output can be eather system.out.println or joption pane, I found the code i need but it uses buffered reader for input not joption pane. Here is the source code
import java.io.*;
import java.util.*;
class MetersToMiles{
public static void main (String[] args)throws
Exception{
// 1 meters = 0.00062137119 miles;
I've got a .csv file with some text and numeric data. I've used BufferedReader to successfully print the data to the console. Now I need to perform mathematical operations on the numerical data. How do I access the data from the BufferedReader in my calculation methods?
What I would like to be able to do is create some loops to calculate totals for some of the elements, but I'm not sure how to access the data from other methods (and potentially classes?).
I am reading each line of the input one line at a time and incrementally storing four char positions into an array, so i am able to hold a vertical representation of each column. I.e. column 1 will be stored in array[0].
The problem with my code is that is does not read the last line of the input, it reads all the other inputs before it but just refuses to read the last line and execute the procedure of storing the characters.
Code:
public void defuseBomb(){ try { BufferedReader reader = new BufferedReader(new InputStreamReader( System.in)); String asciiLine = reader.readLine()+ " "; int digit = (asciiLine.length())/4;
I have a text and I am reading each line in the text with the simple while loop:
BufferedReader br = new BufferedReader(new FileReader(new File(a.txt))); string line = new String(); while((line = br.readLine())!=null){ if(line.equals("john")) //skip to next line else{ //continue something else.. } }
My question is how do I skip to the next line ? Using apache.commons.io.FileUtils; one could easily have done something like this:
LineIterator it = FileUtils.lineIterator(file, "UTF-8"); String line = it.nextLine(); //this goes to the next line..
public static String readBuffer(Reader reader, int limit) throws IOException { StringBuilder sb = new StringBuilder(); for (int i = 0; i < limit; i++) { int c = reader.read(); if (c == -1) { return ((sb.length() > 0) ? sb.toString() : null);
[Code] ....
I am particularly confused with the below lines -
if (((char) c == ' ') || ((char) c == ' ')) { break; }
This is how I am calling this code from my application -
I'm making a tree of contacts with people's names as one string and their numbers as another. I need to read that in from a .dat that is set up to have two columns, across from the names are the numbers, so i have to read that in, but I'm not sure how. Here is what I have:
Tree<String, String> tree = new Tree<String, String>(); BufferedReader br = new BufferedReader(new FileReader("/Users/katedess/Desktop/animals.dat")); String read; while((read = br.readLine()) != null) { tree.add(read); } br.close(); }
I've been working on a saving system for a game I'm working on using java IO writer and reader. When I tried exporting it (as a executable jar) to test I couldn't get it to work, when it worked before. If I had to guess it's the file location not being able to find the file. Which it just looks like :
FileReader end = new FileReader("Saves.txt");
I don't exactly know how to set it up to read the file. I'd tried giving it a look up but I don't know how to exactly word my problem.
ive been working on a poker game in java but seem to have got stuck in my 3 of a kind. What I was trying to do was create a loop that would increment a counter every time time is more than 1 instance of a card, but even if the counter increments and I draw a 3 of a kind it still returns false.
private boolean ThreeOfKind(ArrayList<Card> sortedCards) { Card previousCard = null; for (Card c : sortedCards){ int kindcount = 0;
How would I go about erasing the first buffered image before displaying the second one and eventually a third and fourth so that it appears the image is moving across the screen?
I am trying to read an image I have in the location of my project, So I do this:
When I read it in the try/catch like: BufferedImage image = ImageIO.read(new file(""));
And try to access it after the try/catch, it does not know that image exists, so I need to declare it as a global variable for that class first, and then it works.
public class Gui extends JFrame { private BufferedImage image1; public Gui() { super("MyApp"); setDefaultCloseOperation(EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); initUI();
I wanted to write a method which gets a buffered image as parameter, rotates it 90 degrees clockwise around its top left corner, and then returns it. This method will be call from another method which then draws the rotated image on a rather large background which consists of many other images.
Here is the code I have so far:
public static BufferedImage rotate(BufferedImage img) { int w = img.getWidth(); int h = img.getHeight(); BufferedImage newImage = new BufferedImage(width, height, img.getType()); Graphics2D g2 = newImage.createGraphics(); g2.rotate(Math.toRadians(90), w/2, h/2); g2.drawImage(img,null,0,0); return newImage; }
This method does rotate an image 90 degrees, but when the calling method recieves this image and displays it on the bigger frame, parts of the rotated image is cut. I think because the frame holding the returned image is not big enough. I've tried playing around with the code a lot, chaging the sizes of different images, and trying AffineTransform features, but I have had no luck.
I am writing a java program that takes a FROM image, a TO image, and a ratio (this is a slide bar in the GUI). Here's my code: Java Code:
public static BufferedImage rollUp (BufferedImage from, BufferedImage to, double ratio) { BufferedImage finalBufferedImage = new BufferedImage(from.getWidth(), from.getHeight(), from.getType()); int packedColor = 0; for (int r = 0; r < from.getHeight(); ++r) { for (int c = 0; c < from.getWidth() ; ++c) {
[code]...
So from 0 to 1 (ratio is a double between 0 and 1) the image will "roll up". The effect works completely in the GUI, but the console freaks out at about 0.33 ratio.. This program runs for testing in a class Main and uses a class Splittinimage.. this method is in class TwixPix. When the main class is run, a box pops up with a combo box and a slider. You pick an effect (in this case, roll up) and then slide the slider to set the ratio. The image below those two things performs the effect that was selected. Imagine a PowerPoint presentation slide effect.
private void createTextBox() { Graphics g = Game.getG(); Font font = new Font(fontName, fontStyle, fontSize); g.setFont(font); height = BORDER_WIDTH*2 + g.getFontMetrics().getHeight(); int stringWidth = g.getFontMetrics().stringWidth(dialog); width = BORDER_WIDTH*2 + stringWidth;
[Code] .....
This gets called when ever I want to create my Textbox object however what gets created is a purple box (i know that I have set the array elements to purple to begin with) however when I try to use the drawstring method to "draw a string" I get an image which looks like the gif below. I have changed the text size to various sizes but without success. The string is supposed to say "This is a test" but obviously it doesn't.
How can I write a BufferredImage to an 8-bit .bmp using indexed colors stored in a <String,Color> Hashtable?
I've never used Hashtables before, and I didn't know color indexing existed until now, but I can do most other things in java fairly well.
I'm not looking for code, just the concept, as I really don't know how Hashtables work (although I could figure it out), and how color indexing does. I know how to write image files, just not indexed or with a specific number of bits. I am using Hashtables generated from GIMP.
EDIT: I mainly want to know how to save a BufferedImage as an indexed .bmp.
I am using netbeans to create a hotel booking system, just tessting out code to get the booking information input to a file when the next button is clicked.
Is there anyway I can write a do while statement for this program. I haven't seen anyway to do it anywhere.
Java Code:
import javax.swing.JOptionPane; public class History { public static void main(String[] args) { //First Question: What is the capital of Mexico? String[] question1 = {"Mexico City", "Paris" //The choseable answers are made using String ,"Washington D.C", "Tokyo"};
How do I make the file reader object move to the next line if there is no more input on the line. Here is my text and output file as you can see that my text file column cuts off on the 2nd line after 70. I want to read that next line which is 100 into my labs variable however its reading it into my final exams variable. I'll also post the code but I didn't think it was necessary.
textfile: 100908095 1008070 10070
output: Labs Projects Tests Final Exams 100908095 1008070100 70
[import java.util.Scanner; import java.io.*; public class MyGrades { public static void main (String[] args) throws IOException { int lab, project, test; int finalExam;//Par and Player values
import java.util.Scanner; import javax.swing.JOptionpane; public class Project { public static void main(String[] args) { Scanner input = new Scanner(System.in);
[code]...
This is the Error that i get in console!"Exception in thread "main" java.lang.Error: Unresolved compilation problem: JOptionPane cannot be resolved at Project.main(Project.java:10)"
Here's My code to create multiple JTextfields in a Single Option Pane.
My goal is simple.
Take some input from the user and then store it a TEXT File.
package printer; import java.awt.Toolkit; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import javax.swing.*; public class Database { JTextField name = new JTextField(); JTextField roll = new JTextField();
I am writing a program that has to do with ciphers and cipher shifts. The program itself works fine, but I am having trouble printing out the answers to JOptionPane. I know the basics of JOptionPane, but my problem is this:
Majority of my program takes place in a for loop, and resolves the cipher (it is a basic cipher program) 1 digit at a time. So, only the last DIGIT (I don't know how to convert a digit to a CHAR in JOptionPane) is printed to JOptionPane. Here is my code:
public static void main(String[] args) { String cipher = JOptionPane.showInputDialog(null, "Please enter a sentence or word that you wish to encode or decode. This program uses " + " a basic cipher shift."); int answer = 0; String upperCase = cipher.toUpperCase(); char[] cipherArray = cipher.toCharArray();
I am supposed to be doing a class assignment that calculates the area of a triangle and outputs with JOptionPane. I was able to fix some errors, but it's uncovering more errors.Here is my code:
public class Area { public static void main (String [] args) { double a, b, c; //Input sides of triangle double x; //Perimeter of triangle double area; //Area of triangle StringTokenizer st;
Just wondering if there was a way to change a JOptionPane's display message dependent on the button the user is hovering over. I.e.: Hover option1, shows one message; hover option2, shows a different message, etc.. but within the same JOptionPane (not showing a new one).