I am working on a contact list program with a GUI for a school project.I'm running into all kinds of issues when trying to update the JList in my GUI which displays the contacts.I think my issues are being caused by a lack of synchronization between the contact list that stores the data, and the contact list that is being displayed.I've tried all kinds of getters and setters, passing array indexes, passing array member objects etc.
General rundown of how I want the GUI/Code to work: When I select an object in the JLIst, the fields on the right should display that objects information.When the "Add Contact" button is created, a new blank contact should be created and added to the Contact List, and then displayed in the JList.When a field on the right side of the GUI is updated, the object in the contact list is updated simultaneously (using document listener), and therefore the JList would also be updated.
I have this Contact List program and im stuck on how to make my contact list show their different details. I don't know what to do , I want my program to be like this. What should I do next to make my every entry have different information then show on to the right side of the panel the information when i click the show details button .
I'm trying to get a primefaces data list working and not sure I'm doing this correctly, having a problem with getting this view to display. Here is my xhtml .
This is supposed to be a method that adds stars after each item in the list.
Java Code:
import java.util.ArrayList; public class ClientProgram { public static void main(String[] args) { ArrayList<String> list = new ArrayList<String>(); list.add("the");
[Code] ...
I'm guessing it's because list.size() changes, though but it should only find that value in the beginning, so it shouldn't be a problem?
I wrote displayAscending() and displayDescending() methods to this double linked list and it is not working at all. Logically it seems fine to me. I positioned the head in the beginning in the ascending method; created a variable named data1 as an auxiliar variable so it can store the values that are going to be moved; and moved the values. Same thing for the descending method but instead of the head I put the tail and move left the list, instead of right.
import java.util.*; class node { int data; node left; node right; node(int d, node l, node r) { data = d;
I'm trying to create contact information as object and another object as parcel then calculate the shipping fee. Problem is I don't have a good understanding in implementing object type to my code. Attached are what I've done and I know that my constructor in my parcel class and contact class are probably wrong too but I don't know what to do with it.
//contact class public class Contact { private String Name; private String Address; private String City; private String State; private double Xco; private double Yco;
I have a question about arraylist objects.... I want to create an address book that will contain a persons information (name, phone, address, email..etc..). The first two snippets of code are from the same class ContactArrayList and the last one is from the class Contact. Do I need to create a separate arraylist for each data type? Is it possible to use a single arraylist to contain all the object (person) information and then be searched for using a GUI? I would also like to be able to access this data to be manipulated using a JFrame (add, edit, and search).
public class ContactArrayList<E> implements List<E> { public int size, capacity; E contact; private E[] contacts; public ContactArrayList() { size = 0; capacity = 20;
I'm working on a GUI Phonebook and need getting a button to work for deleting a contact. I identified the error I get in the Gui class where it says applyDeleteEntry(); on line 106 with comments. The entries are stored in a .txt file which is created for you.
Main class:
import javax.swing.*; import java.awt.*; public class Main{ public static void main(String args[]) throws Exception{ Phonebook mainPhonebook = new Phonebook(); Gui mainGui = new Gui();
When I run my program and choose option 2 to get contact details I am expecting it to display as follows (First Name, Last Name): Contacts how have been entered:
0) John Doe 1) George Smith 2) Nancy Davis
Please enter the number corresponding to the contact you would like to view:
Instead for a personal contact it is displaying as follows:Contacts who have been entered:
0) Doe 1 F St. (last name, address)
Please enter the number corresponding to the contact you would like to view:
Instead for a business contact it is displaying as follows:Contacts who have been entered:
0) 1 F St. jd@gmail.com (address, email)
Please enter the number corresponding to the contact you would like to view:
Then when I enter the number to display the contact for personal it is returning me only first name and business is only returning me first and last name. It should be returning the full contact info that was put in during the add contact step. I thought I programmed everything properly but it isn't displaying what I want to seeMy code is listed below.
ContactList
/* * 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. */ package contactlist; import java.util.ArrayList; import java.util.Scanner;
I wrote a code from our text book for Pong. Im trying to figure out how to fill the ball with color. Im also wondering how to speed the ball up once there is contact with the paddle. The initial speed is ok but once contact is made with the paddle, it slows down. Makes it too easy to play. Here is my code so far. As far as the game goes, it works and is good. Just wanted to add a couple customizations.
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.Random; public class FileHandlingDemo {
[code].....
As you can see my Intention is to save randoly generate Integer in the output file And this is not working but if I use Something like this
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class FileHandlingDemo {
[code].....
it's working fine reading that from Input.txt and writing that data in output.txt file. but not in first case Both file are in working directory already created.Where is wrong?
My instructor gave me this code to use as my Array sort. I can not get this to work. I do not get any compile errors, the code just does not do anything.
Java Code:
package inventoryprogram4; import java.util.Scanner; public class Inventoryprogram4 { static GUI mainGUI = new GUI(); static String outText = "";
Here is the program I wrote for calculating the circumference of a circle.
//circumference.java //program that calculates the area and circumference of a circle import java.util.Scanner; //program uses class scanner public class circumference{ //main method begins execution of Java application public static void main(String args[]){
[Code] .....
Even though my code compiles and runs without any errors, the program doesn't calculate the circumference.
Alright so I'm trying to write a code that implements a for loop and if statements that displays any number from 100-200 if the number is divisible by either 5 or 6 in rows of ten numbers each row. If it is not divisible by that number then it should go back to the beginning of the loop until it reaches 200. My main problem is that it doesn't display anything. I don't get any errors or anything but every time I run the program it just displays nothing. Sample output is at the bottom of the code.
public class Exercise5_11 { public static void main(String[] args) { int count = 0; int i = 100; //for (the numbers from 100 to 200) for (i = 100; i>100 && i<200; i++){
I am currently writing two java classes (client and server). The client takes an input number form keyboard and sends it to the server. The server then multiplies this number by two and sends it back to the client. The numbers should also be printed to screen along the way, for example if I input the number 3 I should get
"From Client: 3" "From Server: 6"
They should continuously do this unless a negative number is received by the client, say for example the number -3 is sent to the server and it returns -6.
The code I have for the two classes so far is:
import java.io.*; import java.net.*; import java.nio.ByteBuffer; import java.util.Scanner; class Client { public static void main(String args[]) throws Exception { DatagramSocket clientSocket = new DatagramSocket();
[Code] .....
Currently, when I run the program all I get is an output of the number first entered. I am aware it requires a loop but I don't know where and what the condition should be.
Also if I wanted to adapt this so that it would take the integer from client and subtract two at the server and return to client who sends back to server to keep subtracting two unless it reaches a negative number at which point the client will terminate the program - how might I do this.
I do realise there needs to be a while loop in the above code, but I wanted to test it sent the number from client to server and its not doing it. All I get is a print screen of 'enter number' and then the number I enter.
Working on a program that creates an array from a file, organizes it in various ways, and then prints the results. Right now I'm specifically having trouble with the printAry() method - when I try to run it, I receive a NullPointerException for the active line in printAry() (EDIT: line 102). Not sure which sections are important to this, so I will include the client class and most of the service. I realize that the amount of documentation I included is not necessary, but it is required for the class.
class Lab3StudentAryService { private int count; private Lab3StudentData [] studentAry = new Lab3StudentData[50];
/* @param: none @return: none reads file and converts to array. */ public void fillAry() //constructor { Scanner scan = new Scanner(System.in);
My Computer Programming teacher has given the class a problem that requires the use of var.charAt(), var.length() and while/for. Basically, the problem is that we have to create program that'll show a mirrored or reverse version of the entered word. Like for example, if your input is the word "Hello" (the quotation marks aren't included), the output will be "olleH".
Here's the code:
import java.io.*; public class StringMirror {public static void main (String [] args) throws IOException {BufferedReader scan = new BufferedReader (new InputStreamReader(System.in)); String enteredWord = ""; int lengthOfTheWord = 0; int lengthOfTheWordMinusOneVersion = 0;
[code]....
It is working, but the problem is that after the output, there's this error that says String index out of range: -1.
the program is working but I kind of wanted it to have no errors in the end.
I have a java program which would display a message dialog box. The problem is it would stopped working before even displaying the message dialog box. This is my code.
import javax.swing.JOptionPane; public class HelloDialog { public static void main(String [] args) { JOptionPane.showMessageDialog(null, "Hello World!"); } }
There is a pop-up window which would say "Java(TM) Platform SE binary has stopped working." I am using textpad. What should I do with this?
I'm attempting to make a simple Pythagorean Theorem program (A squared + B squared = C squared) but am running into problems when I write it as object oriented. The darn thing works when written as a simple process, but that isn't Java now is it? Here's the simple:
public class PythagoreanTheorem extends ConsoleProgram { public void run() { println ("Finding C from A and B."); double a1 = readDouble("Input A: "); double b1 = readDouble("Input B: "); double aSq = (a1*a1); double bSq = (b1*b1); double cSq = (aSq + bSq); double c = Math.sqrt(cSq); println ("C = " + c);
the program does not print the list when i select choice 3 it only prints the original 2 elements, same happens if i use if else statements instead of switch statement. Quote public class linklistdemo{
public static void main(String args[]){ while(true) { System.out.println("press one enter element");
I have been working on this Java Gui program and i cant get it to print to the textbox correctly.i originally had it displayed in a dialog window but it would print one integer a time in a seperate window.
I have to make a program on J2Me which I don't have a clue, the question is :
------------- "Initial display is a text box, with a command button "Generate". When the user enters the list type and clicks on the Generate button, the application asks count of elements and gets the elements and finally displays the list." --------------
read a text file that has some polynomials in a specific format and perform an arithmetic expression. This needs to be done using a singly-linked list to store the coefficients of the polynomials. There needs to be two methods, one that adds the two polynomials and one to multiply them. So for example suppose i had the following set of polynomials in the text file:
2+x2-3x3 and 1-x-2x2+3x3
these are represented by 2, 0, 1, -3 and 1, -1, -2, 3 respectively. The of the two polynomials is: 3-x-x2 which is represented as: 3, -1, -1
The product of the two polynomials is: 2-2x-3x2+2x3+x4+9x5-9x6
My code is just echoing the data in the text file and not actually doing any arithmetic.
import java.io.*; import java.util.Scanner; class Node { public int digi1; public int digi2; public Node nxt;
I am trying to write a java program that asks the user for a list of names (one per line) until the user enters a blank line. At that point the program should print out the list of names entered, where each name is listed only once (i.e., uniquely) no matter how many times the user entered the name in the program. I am supposed to use an ArrayList for this problem.
My idea for a solution is to create an ArrayList<String>, read each name, i.e., line, entered and then to see if that name is already in the ArrayList. I created a for loop to check each element in the ArrayList but when I try to assign an element to a string variable I get the error "Type mismatch: cannot convert from Object to String". Not sure why that is happening because the ArrayList is defined as a String list.
I am stuck on what to put in my functions for this question: Write a program to maintain a list of the high scores obtained in a game. The program should first ask the user how many scores they want to maintain and then repeatedly accept new scores from the user and should add the score to the list of high scores (in the appropriate position) if it is higher than any of the existing high scores. You must include the following functions:
-initialiseHighScores () which sets all high scores to zero.
-printHighScores() which prints the high scores in the format: "The high scores are 345, 300, 234", for all exisiting high scores in the list (remember that sometimes it won't be full).
-higherThan() which takes the high scores and a new score and returns whether the passed score is higher than any of those in the high score list.
-insertScore() which takes the current high score list and a new score and updates it by inserting the new score at the appropriate position in the list
here are my functions the insertScore is missing because I am having troubles with it.
public static void initialiseHighScores (int[] scores, int size) { for (int i = 0; i < size; i++) { scores [i] = 0; } } public static boolean higherThan (int[] scores, int size, int newScore) {