Adding Third Party JAR Files To JRE
Oct 4, 2014
Currently on the "File Handling" part of my java journey and came across a tutorial which showed how to copy a file with a single line of code as an alternative to using the core java classes. This involved using classes from the Apache Commons site, but so far I have not had any success in using it properly outside of Eclipse, which I'm staying away from for the time being (I'm using Notepad++).
I'm wanting to add the "Commons IO" library, but I'm guessing there's more to it than simply pasting it the jre/lib or jer/lib/ext folder, because so far my program keeps throwing the same error at compile time.
import org.apache.commons.io.FileUtils;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.File;
public class CopyFile {
public static void main(String[] args) throws IOException, FileNotFoundException {
[Code] ....
COMPILE ERROR
CopyFile.java:1: error: package org.apache.commons.io does not exist
import org.apache.commons.io.FileUtils;
^
CopyFile.java:12: error: cannot access FileUtils
FileUtils.copyFile(inFile, outFile);
^
bad class file: .FileUtils.class
class file contains wrong class: org.apache.commons.io.FileUtils
Make sure it appears in the correct subdirectory of the classpath.
View Replies
ADVERTISEMENT
Jun 8, 2014
I wrote my own class to represent univariate polynomials and it works fine, but I was quite sure I was reinventing the wheel, and should obviously like to extend my program's functionality using other kinds of mathematical object.
I've been looking and there are of course open source libraries available which contain everything I'd want to do myself, and more, and probably better, saving me a lot of work.
However the usefulness of this kind of library extends far beyond simple practice and would be invaluable in developing more complex applications.
If I were to plan to write an application that I would at some point in the future like to compile into an executable and sell, would I need to take care about any open source libraries used that the compiler relies on? If so, would it be possible at that stage to use just the API and write my own classes replicating the functionality to avoid breaking license agreements?
The library I'm looking at right now is distributed under the Apache license.
View Replies
View Related
Aug 31, 2014
I have written a java applet. Few months before It was working all fine but my client has some other requirements now and I have to edit it. I am getting two problems:
1. I could not execute it on my local computer as it always gives "your security settings have blocked a local application from running". I have edited the settings from Control Panel but it is then started giving permission error on including permission in manifest file it started giving trusted library error and still it is not resolved.
2. Can I know how to work with third party library with applets. I have imported the library and uses its few classes but when I tried to load applet it always give no class definition found error. I have some ways mentioned online like use comma separated names for all the jars but no luck so far.
View Replies
View Related
Oct 25, 2014
I managed to retrieve data, and set data in my own ways in which I like. But my problem is, if the file does not contain anything (fully empty), when I try to use my
set("", "");
method, it only sets the last one that is called.
Example:
set("section1", "section1Item");
set("section2", "section2Item");
set("section3", "section3Item");
Only section3 would get set, and not the others.
Otherwise, if the file contained a section already, then each section (section1, section2, section3) would get set.
Here's how I set the data to the file:
public static void set(String section, String data) {
files.openFileWriter();
files.file.delete();
reCreateFile();
String beforeItem = section + ":" + files.dataList.get(section);
[code]....
And here is how a retrieve the data and set them to my arraylist/hashmap:
public void getData() {
String line = null;
openFileReader();
StringBuffer sb = new StringBuffer();
[code]....
View Replies
View Related
Oct 26, 2014
What step to know to develop software..
View Replies
View Related
Apr 13, 2015
In a program I created, I'm using a text file that contains some texts needed for the program. The method relevant to this is something like the following.
private String wordgen(){
try {
BufferedReader reader = new BufferedReader(new FileReader("src/Resources/adjectives.txt"));
Random rand = new Random();
int low = rand.nextInt(400);
String fil="";
int i=0;
while(i!=low){
[Code]...
The program runs fine in netbeans project but once the jar is created it does not corporate with the text file. ("null" is returned) How can I attach text files to jar and exe?
View Replies
View Related
Mar 10, 2015
I need to transformation the txt files into xml files, but each row txt files don't have same elements, for example the first book is composite one author
<books>
<book>Title</book>
<price>price</price>
<author>Author</author>
</books>
but the second book is composite two author
<books>
<book>Title</book>
<price>price</price>
<author>Author</author>
<author>Author2</author>
</books>
I would have the xml files with the number of authors variables, I can use JAXB for my problem?or not?
View Replies
View Related
Jan 1, 2015
I am working on a text based adventure game. (This is NOT OOP at all) The problem comes in at my second if statement inside my loop, it is not adding 1 to my array locations[] it keep printing location[0] then a 1 at the end. Not really sure what is going on here. I would like it to when I type "Go north" it adds 1 to locations[]
E.G
locations[0]
Go north
locations[1]
go north
locations[2]
package com.PenguinGaming;
import java.util.Scanner;
public class Game{
[code]....
View Replies
View Related
Apr 5, 2014
I'm really struggling adding JLabels to my GUI. The code is giving no errors but the JLables aren't showing up as I think I've done something else wrong. Here's my method for adding the JLabels:
public void showGraphics(){
for(int i=0; i<message.length(); i++){
if(message.charAt(i) == '#'){
JLabel localLabel = new JLabel("test label");
getContentPane().add(localLabel);
}
}
}
I think the problem might be to do with how the rest of the GUI is setup and the fact that I haven't specified where to add the JLabel just that I'm adding them.
Here's what my GUI looks like.
I want the JLabels above the JTextArea.
View Replies
View Related
Jul 28, 2014
Code of file:
Java Code: import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
[code]...
The serializable class ImagePanel does not declare a static final serialVersionUID field of type long public class ImagePanel extends JPanel{ ^^^^^^^ ^ ^^2 problems (1 error, 1 warning) mh_sh_highlight_all('java');
im basically just trying to put the image inside the GUI and centre the text underneath it. Which is hard to believe since the text is above the image in the code .
View Replies
View Related
Feb 1, 2014
I'm trying to make a simple program that will show the amount of a bill, the tip, tax and total with all 3 added.
Right now i am having issues with line 12. I am getting the error "Variable amount might not have been initialized
I thought i did initialized it.
import javax.swing.JOptionPane;
public class BillAmt {
public static void main(String[] arg) {
String amt;
double tax, taxTotal, tip, total;
tax = 6.75;
double amount;
taxTotal = amount + tax;
tip = taxTotal *.15;
total = tip + taxTotal;
amt = JOptionPane.showInputDialog("Please enter the amount: ");
amount = Double.parseDouble(amt);
View Replies
View Related
Nov 5, 2014
package calculator;
public class operations {
int a = 5;
int b = 10;
public void add(int a,int b)
{
int c = a+b;
System.out.println(c);
}
}
I am not getting output to this question though it runs.
View Replies
View Related
Mar 25, 2015
I have a supermarket checkout line where i have a list of available products on the left and then a basket on the right with the products in. The products are listed in an array, here is the product class
public class Product {
private String name;
private double weight;
private double price;
[Code] ....
with getters and setters excluded, and the list these are put into
public class productList extends DefaultListModel {
public productList (){
super();
}
public void addProduct (String name, double weight, double price, int code){
super.addElement(new Product(name, weight, price, code));
i have the price for each product to be displayed in a text field with the following code
addBasketItem = new JButton();
getContentPane().add(addBasketItem);
addBasketItem.setText("Add >");
[Code] ....
defaultCheckoutList contains my available items and defaultMainList is the basket, with mainTillPrice being the jtextfield.
This works to get the price however it just replaces each time i make a new entry with the price for the next item, i want a total of the price of all the items i have added, but not sure how.
View Replies
View Related
Mar 11, 2014
how can I add the numbers in quantity where it will automatically put in total?
im using netbeans.
just want the codes for how to add the listed quantity?
View Replies
View Related
Nov 17, 2014
I want to add validation to some of the elements in my constructor.
Person(String idIn, String nameIn, ) {
this.id = idIn;
this.name = nameIn;
}
I want to be able to check that the data for the ID is limited to a certain collection of characters formatted in a certain. For example, I may wish to limit it to 5 lowercase letters or numbers, or a combination of both. How could I do this?
View Replies
View Related
Apr 12, 2015
Here is my program. I have to add the outputs from variable 'done' together. It seems to not work inside or outside the loop.
//A program that will find the last/check digit of a Book ISBN number.
import java.util.*;
public class ISBN {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
System.out.println("Enter the ISBN number>");
String isbn = kb.nextLine(); //Even though the ISBN code is a number,
[Code] .....
View Replies
View Related
Sep 27, 2014
How do i add a ratio into this program. it needs to find the ratio from lowercase to uppercase.
import java.util.Scanner;
public class Strings
{
public static void main(String[] args)
[Code]....
View Replies
View Related
Nov 24, 2014
I wanted to create a interface with buttons ofshapes and type of transformation where user first select a shape, the shape will appear and user will have to click on the buttons on resize, reflect, rotate or skew to transform to shape. How can i do the coding? such as adding listeners to the shapes?
View Replies
View Related
Apr 21, 2014
I am doing a few Spring tutorials and in eclipse and for each tutorial I have to right click my project, build path, and then add external archives and then select the spring JAR files I want to bring in and use before my project will successfully compile and run. I was just wondering is this required for every project or is there a way I can set eclipse up to look in these locations for every project without me having to explicitly tell it too?
View Replies
View Related
Jan 16, 2014
I have been trying my hand at making 2d top down view games and have found myself repeatedly using the same code so i created a file with all the functions so when it is down i just import the jar and dont have to keep rewriting functions. I have trouble because the background is loaded on the screen and i dont know why as i didn't tell it to load. In fact I set the panels visiblity to false. Both of my classes are in the same package. Why I still get the Image.
Walking Turtle
Java Code: import javax.swing.*;
import java.awt.event.*;
public class turtleWalker extends JFrame{
public static void main(String[] args){
JFrame frame = new JFrame("Walking Turtle");
[code]....
View Replies
View Related
Oct 2, 2014
I am trying to add two bytes together in binary. The problem is that I need to print the carryover also. The printed result should be 8-bits long if the byte or the integer converted in binary is less than 8-bits the empty space should be filled with 0-s. I figured out how to print and add them, the part with the filling the blank with 0-s too. how to print the carryover. For example:
byte x =15;
byte y =9;
the output will be :
00011110 - carryover
x 00001111
y + 00001001
__________________
00011000 - result
import java.util.Scanner;
public class Addbytes
{
public static void main(String args [])
[code]....
View Replies
View Related
Nov 27, 2014
I am new to swing and I wanted to know how to be able to make a second row of buttons. Right now I have a text pane at the top and at the bottom one row of buttons. But I need to add another row or two of buttons. I've only been coding in Java.
public class TextPane {
public static void main(String[] args) throws IOException
{
/////////////
//I/O FILES//
/////////////
//Create the input file
FileWriter inputFile = new FileWriter("userInputStory.txt");//story user creates with the <nouns>, <verbs>, etc
PrintWriter inputFileWriter = new PrintWriter(inputFile);
[Code] .....
View Replies
View Related
May 4, 2014
So I'm doing a basic MVC layout for a pretty basic game that I am making in order to understand the whole MVC layout. The game requires the user to move up/down/left/right via JButtons on the GUI. Since I'm using an MVC layout and my buttons are in a different class than the ActionListeners, I was wondering what the best way to add the action listeners are?
Method 1:
View Class ActionListener method:
Java Code: public void addMovementListeners(ActionListener u, ActionListener d, ActionListener l, ActionListener r){
moveUp.addActionListener(u);
moveDown.addActionListener(d);
moveLeft.addActionListener(l);
moveRight.addActionListener(r);
[Code] ....
Which method is better? Is there another method that is even better than these two? Trying to get this MVC thing down.
View Replies
View Related
Apr 9, 2014
I am trying to add an image to this button.
button3 = new JButton();
button3.setIcon(new Image("C:\Users\Owner\Desktop\AUSE.jpg"));
button3.setEnabled(true);
panel.add(button3);
add(panel);
Error I am getting?
BackgroundImageHelper.java:77: error: Image is abstract; cannot be instantiated
button3.setIcon(new Image("C:\Users\Owner\Desktop\AUSE.jpg"));
^
1 error
[Code] ....
View Replies
View Related
Nov 28, 2014
I am making a graph to implement Breadth First Search and Depth First Search. I changed the program because I want each button to be its own node. However I am having an issue placing them into a panel. When I run the program I get the following error:
The method add (Component) in the type Container is not applicable for the arguments (Buttons)
JPanel matrixPan(){
Buttons[][] matrixBtn = new Buttons[25][25];
JPanel panel = new JPanel();
panel.setSize(550,550);
panel.setLayout(new GridLayout(25,25));
[Code] .....
View Replies
View Related
May 23, 2015
I am trying to create a simple programme that adds two defined matrices together,
public class Question4 {
int [][] numeros1 = { {1,2,3},
{4,5,6}
};
int [][] numeros2 = {{2,5,8},
{3,7,9}
[Code] ....
View Replies
View Related