After installing JDK, I extended my system path to include C:Program FilesJavajdk1.8.0in. However, javac is only recognised if im in directory C: but that doesn't apply to the Java (run) command which works when Im in the sub-directory that has my .class file. Is there a way to make javac work when Im in a sub-directory?
I am very Java illiterate and I need to know how would i set all the variables in the first class to null or 0 to make a new method to clear everything.
import java.util.Arrays; import java.util.Scanner; public class studentMethods { private double totalScore; private int count;
Here are two codes that I am using but I have one that just doesn't work for some reason and the other does. Encode doesn't work. I don't need the Character.isAlphabetic for encode but not sure what I can use with 'if' to set the String encodedString.
I have been playing around with a snippet I wrote to get the Label on a drive (below). It works fine for me (though I will take any constructive criticism). My question is whether the is a way to set the drive label, purely with Java. I know I could call command line, or even resort to using the Windows API
I tried using this since the jSpinner's minimum value is 1.. (I want it to reset the jSpinner after updating the database):
jSpinner1.setValue(new Integer(1));
But gives me an error:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1 at java.util.Vector.elementData(Vector.java:730) at java.util.Vector.elementAt(Vector.java:473) at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:649) at shop.jSpinner1StateChanged(shop.java:267) at shop.access$100(shop.java:22) at shop$3.stateChanged(shop.java:145) at javax.swing.JSpinner.fireStateChanged(JSpinner.java:457)
JFrame{ JPanel(That MenuBar at the top) JPanel(That panel at center with table){ JScrollPane{ JTable } } }
I want to add my custom image to that grey space right there. I guess it is a JScrollPane, because I added that orange background on JPanel that contains it. But when I add this code to my custom class of JScrollPane:
@Override public void paintComponent(Graphics g) { super.paintComponent(g); if(background == null){ background = new ImageIcon(ClassLoader.getSystemResource("tableBg.png")).getImage(); } g.drawImage(background, 0, 0, null); }
The result is the same, no changes.
Then I read some documentation. I found this method:
scrollPane.getViewport().setBackground(Color c);
It works, but it accepts only color and I want to add image. Is there any way to do that? Do I need to subclass JViewport and use paintComponent ? If yes, then how to make getViewport() method return my custom subclassed version?
I have a PDF file and I have a text file that contains this data. It has the name of a PDF field along with a database table column name.
Text file: pdfFieldEmployee=Employee; pdfFieldStartDate=StartDate; pdfFieldSalary=Salary; pdfFieldExempt=Exempt
I also have this hash map that contains the database table column names along with their corresponding values:
Employee, Don Parker StartDate, 5/6/2000 Salary, $55000 Exempt, N
How would I read through the text file and the hash map and at the same time do this:
if the pdf field is equal to pdfFieldEmployee, then set pdfFieldEmployee equal to Don Parker. if the pdf field is equal to pdfFieldStartDate, then set pdfFieldStartDate equal to 5/6/2000.
and so on and so on. I would prefer to do this with a loop because I think it would take less code than writing a bunch of if statements.
This is my frame class, now I want to be able to change the name of the frame, and get the name with frame.getName() in another class. But I'm not sure how to do this, i tried making a new frame in that class but i feel it's just another frame and not the one i made, also tried something like
This is my code and it works! But how/where do I set a background image for it to appear as the background of my calculator? The code I have for it is this -
import javax.swing.*; import java.awt.*; import java.awt.event.*; /** * Program using SWING components to create a Christmas themed Calculator. */ public class ChristmasCalculator implements ActionListener
When I try to brighten my BufferedImages with RescaleOp, they are cut in half, and not brightened at all. However, strangely enough, when I tried to run the same program on another computer they were not cut in half, but only one half of the image was brightened. Here are two images displaying the issue:
Before brightening:
After brightening:
Why does this happen? Are the images not loaded properly, or am I simply not using the class correctly? Here is my code:
Java Code: ...
RescaleOp op = new RescaleOp(1.2f, 0.0f, null); op.filter(enemies.get(y).getImage(), enemies.get(y).getImage()); ... mh_sh_highlight_all('java');
I am rather new to Swing, and I am building a game right now in which I need to display a pop-up window as a reminder for what commands exist within the game. I created a class extending JFrame for this and added all the information I need. However, for some reason, no matter how many different ways I try to set the size of this window (setSize(w, h), pack(), using a different layout, adding the compnents to a JPanel first and setting the preffered size of that, then adding the JPanel to the JFrame), it doesn't work. Instead of a window of my requested size, I get a tiny, maybe 100 x 100 pixel window that needs to be resized in order for its contents to be visible.
Recently I have been working on an executable launcher. I tried to get the executable icons and set them on the JButtons. Still there are some problems. Here is a part of the code:
Here the getConfig() method is already defined to get a string in a "properties" file. However, the icons are very small and they don't fill the entire button.
How can the icon fill the entire button (for example, having a custom size of 48x48, or automatically filled the button)? The frame will not be resized.
I have a requirement where I have a class as Page which itself contains ArrayList<Page>.Here ArrayList<Page> is nothing but the pages which are accessible from the base Page.I know the depth level ( reading from file) which means how many level I need to go to identify more pages.BUT the problem is how to set the base Page class. I need to set the base Page class but for that I need the objects for the subsequent pages and hence an iterative type of implementation.
dynamically create tabs by pressing a button, each tab has Primefaces input texts in which i'll be adding stuff and with a Submit button i'm submitting the form.
My issue now is this; although I can create more buttons through my managed bean, I cannot set the ValueExpression to the InputTexts. When I do:
inputName.setValueExpression("value", createValueExpression("#{cdiBean.name}",String.class)); it doesn't work.
The createValueExpression is a static method in my managed bean and it returns a ValueExpression. I'm most certain I found it online, not sure where though, it's been over a month since the last time I worked with this topic.
Anyway, is my whole "methodology" correct? Should I do anything differently?
Is there any class which lets me set brightness to an image, preferably BufferedImage but it doesn't really matter, and then whenever desired remove the brightness. I have tried using RescaleOp, but it doesn't satisfy the latter criterion. When I have brightened the image, I can't seem to get it back to normal.
Java Code:
RescaleOp op; if(image should be brightened){ float scales[] = {2f, 2f, 2f, 1f}, offsets[] = new float[4];
op = new RescaleOp(scales, offsets, null); op.filter(getImage(), getImage()); }else{ float scales[] = {1f, 1f, 1f, 1f}, offsets[] = new float[4];
op = new RescaleOp(scales, offsets, null); op.filter(getImage(), getImage()); } mh_sh_highlight_all('java');
I am getting errors when I try setting left and right values (which are String types) for my tree.I tried doing something like:
Node node = new Node("Is it human?", null, null); node.getLeft().setNode("Is it Zelda?");//the first left Q node.getRight().setNode("Is it Kirby?");//the first right Q
but that gives me a runtime error of "java.lang.NullPointerException" which points to the line 2. I also tried this:
Node node = new Node("Is it human?", null, null); node.setLeft(setNode("Is it Zelda?"));//the first left Q node.setRight(setNode("Is it Kirby?"));//the first right Q
but that gives me another error, pointing to the setNode for both lines 2 and 3,plus it wouldnt make sense since both setLeft and setRight takes in Node types, not String types.
Here is my Node class:
public class Node { private Node leftPt, rightPt;//left and right pointers for Node private String node, left, right; public Node(String node, Node leftPt, Node rightPt){ this.node = node; this.leftPt = leftPt; this.rightPt = rightPt;
I'm having trouble setting up a test for my combination method.Here's the method (It basically finds the most amount of characters that both substrings share and combines the two using the number of shared characters as a breaking point):
public static String combination(String str1, String str2, int overlap) { assert str1 != null : "Violation of: str1 is not null"; assert str2 != null : "Violation of: str2 is not null"; assert 0 <= overlap && overlap <= str1.length() && overlap <= str2.length() && str1.regionMatches(str1.length() - overlap, str2, 0, overlap) : "" + "Violation of: OVERLAPS(str1, str2, overlap)";
In NetBeans IDE >> Palette Window >> JFrame properties, I set the background color to (for example) blue but when I run with F6 key, the appearing window is always at gray color. Why?
I didn't work a lot with Reflection and now I'm having troubles by writing a method to set a field value of an unknown type.
I wrote a little example program to show, where I cannot find a solution. I explain the problem in the following points:
- there is a class with 4 fields, which 2 are of type primitive int and 2 are Integer - at line 27 is set the name of the field I want to modify - if is set field1 or field2 (of type int) there is no problem. In this case the 'case "int"' of the following switch is executed - if is set field3 or field4 (of type Integer) is executed the 'default' case of the following switch and at line 56 is thrown the cast exception that "Cannot cast java.lang.String to java.lang.Integer"
import java.lang.reflect.Field;
public class TestClass { public int field1 = 1; public int field2 = 2; public Integer field3 = new Integer(3); public Integer field4 = new Integer("4");