I'm stuck with a problem. The code below generates a coloured image.
//Setting the size of the graphics window
final int WINDOW_DIMENSION = 200;
final int SIZE_FACTOR = 3;
EasyGraphics generate = new EasyGraphics(WINDOW_DIMENSION*SIZE_FACTOR,WINDOW_DIMENSION*SIZE_FACTOR);
//Constructing the arrays
char[][] firstArray = new char[WINDOW_DIMENSION][WINDOW_DIMENSION];
char[] secondArray = scan.toCharArray();
[Code] ...
What I would like to do is generate a picture which is mostly white but the colour boundaries of the original picture are in black. I tried using the code below but it doesn't produce what I wanted.
for (int a = 1; a < WINDOW_DIMENSION; a++) {
for (int b = 1; b < WINDOW_DIMENSION; b++) {
generate.setColor(0,0,0);
if(firstArray[a][b]!=firstArray[a-1][b] || firstArray[a][b]!=firstArray[a][b-1])
generate.setColor(255,255,255);
generate.plot(a,b);
}
}
I've been assigned to create a Black Jack game with a gui. In this game I've created a seperate Player and Dealer class, and both initiated them, however when I try to call a Player object in a certain way I get a null pointer reference. (It should be noted that the Player object is an array)
public void runGame(){ while(running){ while(dealer.getPoints() <=19){ int count=0;
[Code] .....
And this is how I've initilized the Player class in the constructor
Player[] players = new Player[numberofplayers]; for(int i=0; i<numberofplayers; i++){ players[i] = new Player(i); players[i].setDeck(d1); gui.add(players[i].getPanel()); }
What I don't get is if I change players[i] to dealer, it works fine.
I'm making a program that selects classes from a database via a jcombo box and then populates a time table with the class times.
I've used a custom cellrenderer that extends DefaultTableCellRenderer to text wrap the information and change the background of the cells.
It works but when i minimize the program it goes all black and if I double click I get a new JTextArea opening up on the timetable and when I minimize the program and go to open it again i get an "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" and the cell render seems to be called again even though i haven't rerun the program.
This is the cell renderer that I built
public class TimesTableCellRenderer extends DefaultTableCellRenderer { private int minHeight = -1; private final JLabel label = new JLabel(); private final JTextArea textArea = new JTextArea(); public TimesTableCellRenderer(){ super(); textArea.setLineWrap(true);
I wrote this code which print a black image depends on the number of rows and columns you give it
public class BlackImg { private Mycolor[][] colorArr; //Mycolor is a class i wrote that represents colors. // no need for showing the class here. // so i created here an array of type Mycolor, for example: // { {(255,255,255), {(127,127,0)} }
[Code] .....
my problem is that my output comes good except the last line ,
Output: (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) (0,0,0) BlackImg@1db9742 //what is this line , why does it showing up ?
I'm trying to make a code that will draw "roses" using polar functions. The code below is what I have, but when I run it nothing happens. What's missing?
package rose; import edu.princeton.cs.StdDraw; public class Rose { public static void main(String [] args) { int N = Integer.parseInt(args[0]); StdDraw.setCanvasSize(512, 512);
I am working in jsf application, in that one requirement is present. If we click "Take picture" button using webcam from web browser, image has to be captured and displayed in the screen. Finally by clicking save button picture has to be stored either in Database or in File Folder.
I am trying to learn Java and while i was playing a bit with the basic knowledge that i have i encountered a problem. When i run the program, the lines and the picture appear in two separate windows when i compile the program. how can i make them appear in the same? The code is this:
public class Game { private int x; private Picture pic;
I've been trying to post background picture for a long time in java. I've just finished writing breakout game and I want it to be more special and full of interesting things. I want to upload picture in java. I write
GImage image= new GImage("LEONARDO.JPG"); image.setSize(50,50) add(image,200,400)
import javax.swing.*; import java.awt.*; public class PRJ04 extends JFrame { public static void main (String [] args) { PRJ04 frmApp = new PRJ04(); PanelChart pnlChart = new PanelChart();
[Code] .....
When I comment out the adding and setting of the pnlChart on my main driver, the pnlPopulationInputs shows up fine, and it runs ok. When I add the pnlChart I get errors like crazy and a white screen. My errors:
Exception in thread "AWT-EventQueue-0" java.lang.ArithmeticException: / by zero at PanelChart.drawChart(PanelChart.java:45) at PanelChart.paintComponent(PanelChart.java:24) at javax.swing.JComponent.paint(JComponent.java:1054)
[Code] ....
Once more with this one, I refer back to our in class example. Our programs are set up the same, yet he has no issues with the "/ by zero" exception.
What I am doing is loading a new image from resources in my project, so that I can get the size. Using this, I create a new BufferedImage with those dimensions. The following code is what I am using to take the original BufferedImage, and scale it.
Java Code:
public ImageIcon getBackImage(){ before = new BufferedImage((int)img.getWidth(null), (int)img.getHeight(null), BufferedImage.TYPE_INT_ARGB); int w = before.getWidth(); int h = before.getHeight(); try{ URL url = getClass().getResource("/Blue_Back.png"); before = ImageIO.read(url);
[Code] ......
The scaling seems to be working fine, but what I have noticed is a line of approximately 10 pixels at the top of the image. I took the original image and blew it up to ensure that I wasn't just enlarging undesired portions and this wasn't the case. I then tried to fetch a subImage of the BufferedImage, and that also left the padding at the top. Is there something I am missing that is placing this undesired padding at the top of my bufferedImages ?
PaintWindow pw = new PaintWindow(); Random rand = new Random(); ImageIcon image = new ImageIcon("C:/Users/Ghostkilla/Desktop/gubbe.jpg"); setWidth(pw.getBackgroundWidth()); int height = pw.getBackgroundHeight();
[Code] ....
If you run this code it will move a picture from right to left and hit the left wall and then go to right again leaving the window (It stops there). I want to make so it hits left and then right wall continuously till someones close the window. So basically I am using a for loop to make it go left right all the time.
How to make so the picture moves from bottomleftcorner to toprightcorner diagonally without leaving the window.
I'm trying to save a picture from byte arrays using RandomAccessFile. The file appears but doesn't open (like its corrupted).
I'm using the bittorent protocol which gives a SHA-1 hash that I compare all the bytes with to verify the data. All the bytes pass the hash check and all the hashes are checked. So I'm pretty sure I'm getting all the bytes correctly.
Is there anything I can do that could tell what's going wrong?
public RUBTClient(final TorrentInfo2 tInfo, final String outFileName) { ... this.outFileName = outFileName; File destined = new File(outFileName); try { destined_file = new RandomAccessFile(destined, "rw"); destined_file.setLength(tInfo.file_length); } catch (FileNotFoundException e1) {
My method below works fine to print a matrix but when it prints every row, it is printing extra 4 white spaces which is not required. How can I delete those extra spaces at the end? when I use
When I open applications specially high graphics applications, the screen flashes with whole black display with a number of horizontal white lines then after 2 or 3 flashes it opens the desired program. What is the cause, is it low graphics memory, physically damaged screen or ?
I have to write a program that will read a picture and then print out the number of blocks inside it.
I have to read the picture as a binary matrix of the size r - c (number of rows times number of columns). The blocks are groups of one or more adjacent elements with the value 1.
- Blocks are built exclusively of elements with value 1 - Each element with value 1 is a part of some block - Adjacent elements with value 1 belong to the same molecule.
We only take into account the horizontal and vertical adjacency but not diagonal.
INPUT:
In the first line of the input we have the integers r and c, separated with one space. Then we have the r lines, where each contains s 0's and 1's. The numbers inside the individual lines are NOT separated by spaces.
The OUTPUT only print the number of blocks in the picture.
import java.util.Scanner; class Blocks{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); char ch[][]; int rowNum=sc.nextInt(); int columnNum=sc.nextInt();
Here is the code, I just wanted to draw a simple yellow rectangle in white background...
import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; public class NewEmpty extends Jframe { Rectangle test = new Rectangle(100,100,100,100); public NewEmpty()
[Code] .....
Errors in the compiler ( i think there's something wrong with that Jframe)
init: deps-jar: Compiling 1 source file to C:Users****Gametestbuildclasses C:UsersMarcoGametestsrcgametestNewEmpty.java :6: error: cannot find symbol public class NewEmpty extends Jframe {
I have a filechooser that works how it should and if anyone enters anything with a dot that isnt .xml it shows an invalid file name message. However when I dont choose a file and press cancel it still says that because when my boolean hits false it's the first thing it hits in that section of code.
if(!writeSuccess) { //display output messages in JOptionPane JOptionPane.showMessageDialog(null,"Error, file name invalid", "Error", JOptionPane.ERROR_MESSAGE); } else { JOptionPane.showMessageDialog(null,"Export successful", "Success", JOptionPane.INFORMATION_MESSAGE); //close the form me.dispose(); }
If I want it to just close down without it saying anything is there sort of if statement I could do that would prevent this? But if it is an invalid file name it will still show that message?
If I "embed" a ProgressIndicator inside a ListView it has an ugly border and a white background. It looks like there's a TextField below the ProgressIndicator.
Why does it behave like that and how to solve it so that the progress indicator is transparent.
I am unable to clear disappear the background of .png image added in a translucent JPanel. I have tried it using JLabel but the image added is with white background. How can i get rid of this white background...
import javax.swing.*; import java.util.*; import java.awt.*; public class HomePage { JFrame frame; JPanel pnl1, pnl2, pnl3; JLabel lbl;