Object Contains Manipulation Code?
Mar 9, 2014 "Object contains data and code to manipulate that data."
Is the statement right ?? as far as i know object only contains copy of instance variables.
"Object contains data and code to manipulate that data."
Is the statement right ?? as far as i know object only contains copy of instance variables.
I am working on a project using pictures and am having some trouble. My assignment is to take a jpeg, and reflect it(over an imaginary x-axis so to speak). As this is my first time working with images, I am very lost. My approach was to take "pixel 0" and have it swap places with "pixel max". Theoretically, I believe I would only need to do this for the first 50% of the pixels, as each flip works on 2 opposite pixels. With my code thus far (the reflect() method), I print the left half of the image. Note: I must use pixel manipulation. I cannot use graphics.
public class MyArt
{
private Picture image;
/**
* Create an Art object using the jpg or bmp at the indicated location
*/
public MyArt(String filename)
{
image = new Picture(filename);
[Code] .....
Working with some code that displays the random movement of an object such as Move 1: (0,1) Move 2: (10,99)?
I need these methods in the class
void initialize( int xPos, int yPos)
void moveLeft()
void moveRight()
void moveUp()
void moveDown()
int getXPosition()
int getYPosition()
I have made a code that should allowed me to move an object in a frame, using the arrow keys. But I don't know why, is not working.
package joc;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.ImageIcon;
[Code] ....
I wanted to ask is there any way that Java code can get at the address of some object or other datum? I've found this useful a few time with certain high performance C# libraries that I've developed.
Also does Java have the equivalent of C#'s "fixed" buffers? which are inline contiguous arrays of primitives (like Chars or Ints etc).
i need to run a piece of code which is inside a string object..is it possible?if so how?
View Replies View RelatedI currently have an on going project of making a gameengine and am currently doing a lighting engine. How to create simple algorithm of explain to me the concepts of creating a algorthm to do a task, like explain how to get the hue saturation and brightness. This preferably needs to be done in java for me to copy the code but as long as i have a concept to go by I could probably translate the code over so it's not to much of a problem.
View Replies View RelatedI'm currently starting my thesis where my Project will involve creating a diff and merge tool for simulink slx files. These are built using several xml files, a png and sometimes some other data files. One can get to these files by changing the file extension to zip.
I am a bit troubled by this since I want to be able to handle all these files simultaneously and hence need to do this automatically when choosing the slx file.
I have a jpeg that I need to print a border around. My plan was to take the jpeg and throw it on top of a second image that is a few pixels bigger in each direction. Currently, my code prints the image with a white border on the right and bottom sides. Is there a way to print the border on all sides, and maybe even make it a more distinct color? I am not allowed to use graphics. I can only manipulate pixels. Here is the basis of my code.
public class MyArt
{
private Picture image;
/**
* Create an Art object using the jpg or bmp at the indicated location
*/
public MyArt(String filename)
{
image = new Picture(filename);
[code]....
I have a string and i need to do some manipulation with that. I have tried couple of things but not sure if those are feasible or not. Here is the situation:
uid=aa,bb,ou=people,cn=administrativeldap,cn=punit.punit.a-12-m020.20,o=ttt
I want the value of uid from this string, actually it's user id.
This particular string i want :: aa,bb
Things which i have tried:
I was trying it in this way string start with uid and ends with ou, but in this case user name itself can have ou, so in that case it breaks. Another approach i was thinking of is splitting the string by = which gives me aa'',bb,ou at first position and then i will again split this string to remove ,ou. but i am not sure if this approach is good or not?
I need to create an java 2D application for the manipulation of image. I saw the JAI library but it can not install it properly, I also copied the jar but I can not find the solution. How can I do? there is a replacement for JAI? what other libraries can I use?
View Replies View RelatedI have to write a program that asks the user to enter the name of their favorite city and use string variable to store the input. The program should display the following:
-The number of characters in the city name
-The name of the city in all uppercase letters
-The name of the city in all lowercase letters
-The first character in the name of the city
However, I can't seem to get past the following errors;
Programming Challenge #12.java:37: error: variable cityFirstChar is already defined in method main(String[])
char cityFirstChar = city.charAt(0);
^
8 errors[CODE
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
[/CODE]
My code is as follows:
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
[code]....
I am suppose to create a rectangle and I have created two classes; Rectangle.java and RectangleTester.Java.
So far my code for the class Rentangle.java is:
package edu.sbcc.hw2;
public class Rectangle {
private int width = 25;
private int height = 25;
public rectangle(int xcoord, int ycoord, int thewidth, int theheight) {
this.width = width;
this.height = height;
}
public int getWidth() {
return width;
So for my assignment I need two instance variables for height and width for which I have, but it says in the assignment I need methods (settings and getters /mutators and accessors that allow manipulation of my instance variables which is a little confusing. Do I put these methods on Rectangle.java or RectangleTester.java.
The same goes for the calculateArea, where am I suppose to put this?
I do have a quick question about string manipulation. You see I've been given a simple exercise that involves asking the user to input a number between 1,000 and 999,999 and displaying the result. Simple enough, but the caveat is that if the user keys in the comma, say 24,000 instead of 24000 for example, the program is not to display the comma. I don't see how to do this without an 'if' statement. The book says the 'if' is not necessary but does offer this hint: "Read the input as a string. Measure the length of the string. Suppose it contains n characters. Then extract the substrings consisting of the first n-4 characters and the last three characters."
What good is n-4 going to do if the string's lengths varies?
Here's what I have written thus far:
import java.util.Scanner;
public class P13
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Please enter a number between 1,000 and 999,999: ");
[Code] .....
I am attempting to use JLists to complete a program that models how operating systems manage processes. A quick synopsis of what it is supposed to do. Each process is to have a priority level (I chose to do 1 -3 with 3 being the most important) and there are supposed to be three lists. One for ready processes, blocked processes, and a running process.
My issues:
1) when I block a process it does indeed switch lists but when it is copied into the blocked list it pulls the element number instead of what the actual process number is. For ex: Say the ready list has 5 processes / I delete 2 / Leaving process 1, 2, 5. When I block 5, it gets registered in the blocked list as process 2.
2) I can't figure out how to give a label to each of my scroll panels (JLists) to signify which box is ready / blocked / and running
3) My switch button - I have commented in what I need to do but don't know how I am going to do it.
Below are my files:
Main
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class PQueue {
public static void main(String[] args) throws InterruptedException {
[Code] ....
I'm playing with vectors for the first time... What I'm trying to do is to allow a user to input one or more integers and store them in a vector for manipulation later on in the program... Here's the portion of the program I'm working with:
Java Code:
package com.itse2317;
import java.util.*;
public class VectorTest
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
[code]...
My question is this: Is there any way to move from inputting integers to printing them, without entering a non-integer (for example, hitting enter)? I looked at the API for the Vector class, and either I'm not thinking about the problem the right way to be able to find an answer, or it's just not there.
Sir, I'am new to Swing Programming. I have to create an application where an image is displayed on one Label. The same image has to be split in parts and stored in database pert wise. Later the user has to retrieve the entire image by viewing a small part of the image. I have already displayed the full image on the Label, now i don't know how to split the image and store it part wise in the database.
View Replies View RelatedCreate an equals method that takes an object reference and returns true if the given object equals this object.
Hint: You'll need 'instanceof' and cast to a (Geocache)
So far I have:
public boolean equals(Object O){
if(O instanceof Geocache){
Geocache j=(Geocache) O;
if (this.equals(j)) //I know this is wrong... but I can't figure it out
return true;
}
else return false;
}
I think I have it correct up to the casting but I don't understand what I'm suppose to do with the this.equals(). Also I'm getting an error that I'm not returning a boolean... I get this all the time in other problems. I don't get why since I have to instances of returning booleans in this. "returns true if the given object equals this object" makes no sense to me. I assume the given object, in my case, is 'O'. What is 'this' object referring to?
I was a bit confused of the code generated by the Axis2 Code Gen.
I have created a logIn(String username, String password) method in my service and used Axis2 Code Gen to generate the Stub.
I try to access the logIn method from my Client using the Stub like below:
TestServiceStub stub = new TestServiceStub("http://localhost:8080/axis2/services/TestService");
String test = stub.logIn("user","pass").
but instead of UserName and password as the parameters, the Stub created a Login object as the parameter for the logIn method. like the one below:
stub.logIn(Login login1);
I wanted to try the logIn method by providing a static userName and password but it seems impossible because the Stub changed the parameter for the logIn method.
how to test the logIn method.
The code here I have works fine if I just want to ask the user to enter four digits: //java application that asks user to input binary numbers(1 or 0) and convert them to decimal numbers import java.util.Scanner; //program uses class scanner public class binarynumber{
//main method that executes the java application
public static void main(String args[]){
//declares variables
int digit;
int base=2;
int degree;
double decimal;
int binary_zero=0;
int binary_one=1;
//create scanner for object input
[code]....
The thing is, I want the java application to input more than four digits for the user and I want it to loop it manytimes f until the user ask it to stop.
I need to create a Java program that takes an input a color code in HSV and outputs the equivalent RGB code and Vice versa.
Example:
If you test on the color RED in RGB:
Input: (255,0,0)
Output: (0,100%,100%)
If you test on the color RED in HSV:
Input0,100%,100%)
Output: (255,0,0)
I am new to Java and have read books, the Java docs, and searched the Internet for my problem to no avail. I have an Array of objects that contains strings. How can I get the object's strings to print in a list so that the user can select that object to manipulate its attributes? For example, the user can select "Guitar 1" from a list and manipulate its attributes like tuning it, playing it, etc. I have a class called Instruments and created 10 guitar objects.Here is the code:
Instrument [] guitar = new Instrument[10];
for (int i = 0; i < 10; i++) {
guitar[0] = new Instrument("Guitar 1");
guitar[1] = new Instrument("Guitar 2");
guitar[2] = new Instrument("Guitar 3");
guitar[3] = new Instrument("Guitar 4");
guitar[4] = new Instrument("Guitar 5");
guitar[5] = new Instrument("Guitar 6");
[code]...
can a keyevent in java make the space ship and the laser too ?
View Replies View RelatedFor example I create an object like this:
BankAccount b = new SavingsAccount();
Now lets say that I want to access a method 'addInterest()' that is in the 'SavingsAccount' class I would have to do: '((SavingsAccount)s).addInterest();'
The question I have is why do I have to cast 'b' to SavingsAccount? Isn't the actual object reference of 'b' already an instance of 'SavingsAccount' class? How does the 'BankAccount' affect the object itself? I'm really confused as to what class is truly getting instantiated and how BankAccount and SavingsAccount are both functioning to make the object 'b'.
I don't understand why the object reference variable 'a' cannot be recast from a thisA object reference to a thisB object reference.Is it the case that once a reference variable is linked to a particular object type then it cannot switch object types later on.I am facing the Java Associate Developer exam soon and I am just clearing up some issues in my head around object reference variable assignment,
class thisA {}
class thisB extends thisA { String testString = "test";}
public class CastQuestion2 {
public static void main(String[] args) {
thisA a = new thisA();
thisB b = new thisB();
[code]....
I am trying to get this to where I can type in a name and it will search through each object and print back the corresponding object info.
Java Code:
import java.util.Scanner;
public class MyPeople {
public static void main(String[] args) {
Person[] p = new Person[] {
new Person("Chris", 26, "Male", "NJ", "Single"),
new Person("JoAnna", 23, "Female", "NJ", "Single"),
new Person("Dana", 24, "Female", "NJ", "Single"),
new Person("Dan", 25, "Male", "NJ", "Single"),
new Person("Mike", 31, "Male", "NJ", "Married") };
[code]....