I'm writing my first bigger program (mysql connection and the first thing bigger than 300 lines ). What I'd like to do is to render data from MySQL using JTable - I managed to handle all the queries but I don't know how to update the table on screen. I've tried to use repaint() but nothing happened. I'm not posting whole code because you'll probably not interested, below are the most important things. I thought about using TableModel but how.
public class Main implements ActionListener{ JTable table;
public Main() { JFrame frame = new JFrame("Frame"); frame.setLayout(new FlowLayout()); frame.add(table);
The intent of the code is to read date from a file, does calculation and then displays that data in a table format on the screen. Then creates another file with those values:
Reads file: Beginningbalance.txt Displays Data with calculation Creates a file called "Newbalance.txt" with the following values:
111 251.41 222 402.00
With the way the code is written I can get it to create the file but it only displays one of the customers (111). I know that I need to create a loop but I am not sure how to build that. I tried creating another while loop and changing it to outFile but that was without success.
import java.io.*; import java.util.Scanner; import java.text.DecimalFormat; public class Output { public static void main(String[]args) throws IOException {
It works in the first time. But, after sometime the data is not retrieved and display empty screen. Once, i stop and start the server again, the data is getting retrieved again. But, later when we refresh the empty page is getting displayed again.
I am writing a piece of software to display an image on the screen using a particular library. The library lets me create an Atlas out of texture file data, to fetch Textures out of the Atlas using the textures' names, and to draw the textures by calling Renderer.draw(texture). It doesn't make a great deal of sense to create more than one of an Atlas or Renderer. I previously designed my code as follows:
public class SystemAssets { static Atlas atlas; public static void initializeAtlas(String pathToTextureFiles) { atlas = new Atlas(pathToTextureFiles); } public static Texture getTexture(String textureName) { return atlas.getTexture(textureName); } }
Similarly, I made a TextureRenderer class whose sole purpose is to provide static access to a Renderer. But many people seem to say that opening up a class like this to global access is bad. I cannot think of any better alternative, however. My core update/draw logic currently works something like this:
public class Game extends AbstractGame { public void init() { Screen current = new FirstScreen(); TextureRenderer.initialize();
[code]...
Making a Renderer object belong to the Game or Screen class doesn't make much sense to me, as there doesn't seem to really be a 'has-a' relationship between them; it's more of a 'uses-a', so that seems to imply that it would be best to just call Renderer.draw(thing) from outside the class rather than making it a data member. This would make my main code essentially call the various methods in order to get or print some form of data, much like System.out.println(). And of course, making one of the classes a subclass of Renderer makes even less sense. But making data members static for the purpose of global access and using singletons are often cited as 'bad' programming practices. This problem also arises in a lot of other scenarios in my program, ie. when I want to serialize Thing data members like texture filenames; do I put the serializer as a static data member in a class for global access and call it like I would a function, or do I put it in a class? And it seems like the Renderer will have to be initialized at the start of the program, which would take place in the init() method in Game, then be used to draw Textures in the Screen, so it would have to be accessible from both locations.
edit: In case it's suggested to put these in the main class, that's unfortunately going to be difficult without using static variables; the library recommends having the main class creating an Application object, which is essentially a black box that actually does all the work of calling Game's init() and draw() methods (via a Game object passed into its constructor) and looping until the program exits. AbstractGame and Screen are classes supplied by the library, so it doesn't seem like I can easily give Game any data that AbstractGame doesn't specifically ask for.
I need making the toString() method return a String rather than display a message to the screen. Also, I'm not supposed to call the toString method in my demo class to test it, so what should I do instead?
public class cupDispenser { String location; int noOfCups; cupDispenser(String location,int cups) { this.location=location; this.noOfCups=cups; } public String getlocation()
Write a program that will read two numbers and an integer code from the keyboard. The value of the integer code should 1, 2, 3, 4. If the value of the code is 1, compute the sum of the two numbers. If the code is 2, compute the difference (first number minus second). If the code is 3, compute the product of the two numbers. If the code is 4, and the second number is zero, compute the quotient (first divided by second). If the code is not equal to 1,2,3,4, display an error message. The program is then to display two numbers, the integer code and the computed result to the screen
here is the code that I have so far:
public static void main(String[] args) { Scanner read = new Scanner (System.in); int num1, num2, code, sum; System.out.println("Please enter a number"); num1 = read.nextInt();
Write a program that will calculate the cost of a ticket order and display the receipt for the customer on the screen. There are 2 ticket prices: adult, and senior citizen. Adult seats are $4.50 and senior citizen seats are $3.50. If more than 5 senior citizen tickets are purchased, the customer gets an extra 20% off the of the ticket order. If more than 10 regular seats are purchased, the customer gets an additional 10% off the cost of the order. A customer can only place an order for one type of ticket. Output the type of ticket purchased, the number of tickets purchased, the gross cost, the amount of the discount, and the final cost of the order.
I am having errors with incaompatible varriables comparing float with doubles.
public class lab3 { static Library myLib; public static void main (String [] args) { Library myLib = new Library(); //Instance the Library class int ticketNum; //Number of Tickets
When I am entering the student name , his/her details should be retrieved from database by servlets and the data to be print in jsp pages this what I want But I am unable to display the data from database in jsp pages .
I think I need to save the file into an object but I cannot seem to figure out how. I tried to save it into a string array but that did not work either. I have been working on that section for three weeks and cannot get it to display correctly.
public class DVDList2 { private static void CreateGUI(){ File file = new File("C:UsersaprildesktopDVD.txt"); JTextField txtName, txtSeason, txtSearch, txtMain; JFrame frame = new JFrame("DVD List"); txtName = new JTextField(20);
Need to display data in a table - no of columns are fixed, and rows may vary based on the data available in DB.Display tables in horizontally and 2 tables per row. If it exceeds 3 it should display in next rowsample format to display attached in attachment,Using JSF 2 & richfaces 4.0.
I am just displaying my values in different ways and I can't seem to get my values to display one at time on new lines. I dont know why that isn't compiling. The part i am having trouble with has the "Not Working" tag in the code.
[highlight=Java] //Trying to figure out how to use /n public class Test { public static void main(String[] args) { int gold= 5; int silver= 3; int bronze= 1;
I'm supposed to take this truth table and alter it so it displays 1's and 0's instead of true false. I'm assumed to do this I would just need to change the variable type and replace true and false with 1 and 0 but every way I try this does not work.
//a truth table for the logical operators.
class LogicalOpTable { public static void main(String args[]) { boolean p, q; System.out.println("P Q AND OR XOR NOT"); p = true; q = true; System.out.print(p + " " + q +" ");
I have an application that displays a GUI and this GUI displays a table with several columns and rows. I have a class that extends DefaultTableModel. I wrote the code that displays the GUI. When the database table changes, how would I updated the GUI dynamically? Do you have any sample code that does that?
We were given a class lab that asks us to write a program that create a multidimensional array ( 5 x 5 ), populates the array using nested loops with letter from A until Y, and displays the array to the screen. and the result should look like this:
A B C D E F G H I J K L M N O P Q R S T U V W X Y
How to write this program.. I have tried all my best but the results are not coming like this..
Budget program. Here is my situation, I have 2 tabs in a GUI, one tab adds a transactions when the add button is clicked, and in the other tab displays a table showing all the transactions. In my code, I want it so that when the user chooses a deposit(combo box variable name = cbType, indexnumber for deposit is 0) it will add to the total and when the user chooses withdraw(index number is 1) then it will subtract it from the total. Here is the code.... (note as well, the code also adds a new row to the table)
So when I tested the program with 2 transactions, the first transaction was a deposit and the 2nd transaction was a withdraw. The end product was that both amounts were subtracted from the total. When I did a withdraw first and a deposit second, the amounts were both added together.
I'm making a game of checkers for my A2 Computing coursework which is due in within a week. I have completely finished the game, and only thing I have left to do is connect the two JPanels together via a CardLayout that I have made. However I am unsure how to do so
I have kept the code I am displaying to a minimal, hence I have removed all the action listeners for my buttons, anyway the problem I have is that, I would like it so that when the user clicks on the 'Multiplayer' button which is the array button ourButtons[1], it will then transition into my main game screen so that the user can then play a game of checkers.
Here is the main important GUI from my CheckerBoard class:
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class CheckerBoard extends JPanel implements ActionListener, MouseListener { // Main routine that opens an Applet that shows a CheckerBoard public static void main(String[] args) { new CLayout();
import java.util.Scanner; public class BellmanFord { private int distances[]; private int numberofvertices; public static final int MAX_VALUE = 999;
[Code] ....
I am trying to display two types of table one with initial cost and another one with new cost. Based on the java code here i already have one table but don't know how to display another table.
Attached is the sample output that i am aiming for. The output table for the above code is:
distance of source 1 to 1 is 0 distance of source 1 to 2 is 4 distance of source 1 to 3 is 3 distance of source 1 to 4 is -6 distance of source 1 to 5 is -1 distance of source 1 to 6 is 2
I need to process one component drag to the table. I misunderstand, how I can see to which Cell fall the component. I tried to use Event and Mouse event handlers in my custom Cell, but they do not work. I can copy the drag event to the table and table handles it, but how to get needed Cell I cant understand.
I am working on an assignment that I can't seem to figure out the final part to. The program takes in course data such as the time the class starts and how long it lasts. The time is in military time (0000 - 2400)
I need the output time to be the time the class started, plus the length of the class, and displayed in military time.
I can't for the life of me figure out how to do this. I have gotten a program that works for this time and minutes, and displays the correct 1020. But when I change the information to say
Start time: 0700 Length = 90 minutes
I get:
Endtime = 90
90 is technically correct, the way the formula is setup, but I need it to display 0900 not 90.
Here is the code that I have. Be easy, I'm still learning, and this is just the file I created to get the formula to work. Also, the verbose in here is just for my own debugging to make sure values should be what I'm expecting them to be.
public class calc { public static void main(String[] args) { double hours, minutes, length; double temp; int time = 2400; hours = time / 100; System.out.println("Hours are: " + hours);
This is my codes in a button that if I click it . that information will send to Jtable but the problem is the jtable is in another frame so how can i connect this ?
DefaultTableModel model = (DefaultTableModel) new admin().tableBagtags.getModel(); if (txtName.getText().equals("")) { JOptionPane.showMessageDialog(null, "Please fill out all fields.", "Error!", JOptionPane.ERROR_MESSAGE);