Applet Painting Is Updating Only When Resized Or Re-maximized

Apr 17, 2014

Pretty much the title. Everything was running fine until a moment, when pain updated only once after the first resize. I've seen some worries about th.start(); or repaint(); but I did not manage to track the problem down since I'm a rookie at programming. Here's the Main class.

import java.applet.*;
import java.awt.*;
public class Main extends Applet implements Runnable
{
// variables
Thread th;
Player player;
static Shot [] shots;

[Code] ....

View Replies


ADVERTISEMENT

JLabel Won't Show Until JFrame Is Resized

Dec 20, 2014

I am trying to make movingLabel move to a different JPanel each time the JButton is clicked. I can see that the random integer is changing each time the button is clicked, but the movingLabel wasn't doing anything. I noticed that if I click the button and then resize the JFrame with my mouse, it shows in the correct panel. Is there something I am missing, or is there a way to make it automatically display in the correct panel without having to manually resize the JFrame each time? I was thinking that I could add something that resizes the window slightly each time the button is clicked to show it, but I don't think that is probably the "right" way to do it.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
public class JMovingFrame extends JFrame implements ActionListener

[code]...

View Replies View Related

JTable Elements Only Show Up When Clicked On Or JFrame Resized

Jan 18, 2015

This is an old project that I had working probably 2 years ago. Since I reopened it the only thing I have changed is the database location. This is a very basic project I did to dip my toes in to Java. I'm going to add it to my portfolio but just to clarify I am not a Java developer so this is mainly there to show that I am not completely blind when it comes to Java.

//Import libraries
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.KeyEvent;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Connection;
import java.sql.DriverManager;

[Code]...

Errors when I click the button that launches the JFrame:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 6 >= 6
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.table.DefaultTableModel.getValueAt(Unknown Source)
at javax.swing.JTable.getValueAt(Unknown Source)
at javax.swing.JTable.prepareRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)

[Code]...

It will launch the window but it will be blank. If I resize the window it will show me the headers. If I click below the headers were the data should be, it will show me the data.

Since it has been so long the only thing I can think of is some of the code has become antiquated. As I said, this was working originally. I just fired it up again to take some screenshots for my portfolio.

View Replies View Related

Swing/AWT/SWT :: How To Create A JPanel That Maintains Same Aspect Ratio When Resized

Feb 23, 2014

I'm trying to create a chess program that uses a JPanel with an 8 by 8 grid layout with 64 jlabels with icons. However, I don't want the icons to be distorted if the user resizes the window in such a way that makes the panel not square. Is there any way I could create a JPanel that maintains a square aspect ratio when it is resized?

View Replies View Related

Painting 2 Components From Different Classes

Jul 14, 2014

I want to make a simple Table Tennis game. I have 2 drawing classes. 1st should draw oval and 2nd rectangle. But second class, which should draw rectangle doesn't work and if i use it together with oval class, then oval doesn't appear too.

Java Code:

public static void main(String[] args) throws InterruptedException
{
Intro i = new Intro();
Pall pall = new Pall();
Laud laud = new Laud();
i.frameID().add(pall); // this adds oval
i.frameID().add(laud); // this adds rectangle
i.frameID().pack();
i.frameID().setSize(400, 400);

[code]...

View Replies View Related

Painting JComponent Onto JPanel

May 13, 2014

I am attempting to make some Java2D shapes by wrapping them in subclasses of JComponent and giving them functionality. Unfortunately after defining paintComponent and adding it to the JPanel the shape is not showing up. As in my last thread the code is mostly irrelevant but the perhaps worth a skim. The only methods truely relevant are the paintComponent method in my shape and Sandbox constructor.

Java Code:

public class Sandbox extends JPanel
{
private Timer timer;
private Circle c;
public Sandbox()
{
c = new Circle();
add(c);
setPreferredSize(new Dimension(400, 300));

[Code] ....

View Replies View Related

Tetris Game - Painting A Custom Shape

Dec 10, 2014

I am currently trying to make a Tetris game, so far I've got a class drawing that extends a JPanel as my canvas, a class Square that is 1 square(20 by 20) and a class LineShape that should draw 4 squares above each other. The class Frame way below is merely to set things up.

Currently i'm able to draw objects of my class Square, so I made a class LineShape that combines both and makes a 4Square long line.

My problem is when I try to draw an object of the class LineShape, it shows nothing, removes what is already painted(the square) and gives an error message:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at LineShape.<init>(Screen.java:96)
at Drawing.paint(Screen.java:79)

I put my classes together so you can copy paste and run, make a new screen to start, to see the problem occur, go to the drawing class's paint method and uncomment these lines:

// LineShape shape = new LineShape(this);
// shape.paint(g);

Below are my classes:

import javax.swing.*;
import java.awt.*;
public class Screen {
private Frame frame;
private Frame inputFrame;
private JPanel panel;

[Code] ....

View Replies View Related

Applets :: Initial Painting - Content Overlap?

Feb 10, 2014

I have 4 small applets on a page that simply prints out the quadratic equation for values passed in. There are 4 applets on a page that have different values assigned. They display fine.... sometimes.... if I refresh or generate new numbers sometimes one applet looks as though it has numbers overlapping the new values. If I resize or drag the browser everything displays fine again - no need to refresh the browser or anything. It's as though old values or something are being overwritten by the new or something similar is happening. What should I include in the paint method of the JPanel that might clear the applet before initial painting happens..... if anything?

View Replies View Related

Swing/AWT/SWT :: Painting Entire Line In Jtable

Apr 1, 2014

I have in my app a JTable. I would like to know how can i do to, when i click in a cell, my jtable paint the entire line of this cell. Here is what i did.

Method call:
private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {
int row = jTable1.rowAtPoint( evt.getPoint() );// Don't know how to send this info through setDefaultRenderer.
jTable1.setDefaultRenderer( Object.class, new RowRender() );

[Code] ....

View Replies View Related

How To Keep Painting Image To Show Smooth Animation

Feb 12, 2015

public void actionPerformed(ActionEvent e)
{
myBuffer.setColor(BACKGROUND);
myBuffer.fillRect(0, 0, WIDTH, HEIGHT);
myBuffer.setColor(Color.red);
for(int x = 17; x < WIDTH; x += 30) //vertical lines

[Code] ....

View Replies View Related

Painting In Swing - Parent And Child Components?

Aug 11, 2014

I keep hearing these two term when it comes to painting in Swing, however, I'm not sure which is which. To my understanding is that the child components are the ones that already exist on screen (could be a JButton, JFrame, or custom painting) . and the parent components are the one to be added/drawn next. (hence, if we override the paintChildren() method when painting, the components that were already on the screen don't appear any more) ....

View Replies View Related

Program That Compute Cost Of Painting And Installing Carpet In A Room

Jan 30, 2015

I need to create a code for this asign:

Write a program that computes the cost of painting and installing carpet in a room. Assume that the room has one door, two windows, and one bookshelf. Your program must do the following:a. Prompts the user to enter, in feet, the length, width, and height of a room.

A. Read the dimensions of the room.

b. Prompts the user to enter the width and heights, in feet, of the door, each window, and the bookshelf. Read these quantities.

c. Prompts the user to enter the cost, per square foot, of painting the walls. Read these quantities.

d. Prompts the user to enter of cost, per square foot, of installing carpet. Read these quantities.

e. Output the cost of painting the walls and installing the carpet.

View Replies View Related

JSF :: Updating Session Value

Apr 29, 2014

I am using JSF2 with Primefaces. Here is my business requirement-Hidden field on JSF page should take the value from the session object that is set in managed bean. Session object is updated every time when the user submits the page. I am able to update the session object in the managed bean and able to get the value in the hidden field first time and after that i see the same value in the hidden field even though session object has different value. Here is the hidden field: <h:inputHidden id="xyz" value="xyz"/> i tried using sessionScope but still didn't work.

View Replies View Related

Updating Value In JTextPane

Feb 20, 2015

I have a jTextPane set up and a panel with radioButtons. My jTextPane displays the contents of a text file I have chosen. The 3rd line, 4th index, displayed in my jTextPane specifies a value of type int. When I click my radioButton, I would like that value to increase by 1. So far, I have the following code. I tried to pane.setText(value + 1), but that doesn't seem to work. How do I update the value and display the updated value in jTextPane?

My code :
 
private final ActionListener actionListen = new ActionListener() {  
for(String line: pane.getText().split("")){     String lineThree = line[3];    
int value =  lineThree.charAt(4);     if(radioButton.isSelected()){      
pane.setText(value+1);     }   }};

View Replies View Related

Interface Not Updating Properly

Mar 20, 2015

The program runs well , it adds the applet but it dosn't update the interface unless I press "_"(Minimize) . To be more clear , the object paints a spring wich goes through 4 stages , it is added to the JFrame but it dosn't uptade until I minimize the frame , that is when it goes to the next stage .

The main class which calls the spring to be added to the frame :

public class principal implements ActionListener ,Runnable{
JTextField field;
JFrame frame;
private class Action implements ActionListener {
public void actionPerformed(ActionEvent event) {
  frame.repaint();

[Code] .....

View Replies View Related

GUI JComboBox With Updating Jlabel

Oct 18, 2014

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

[Code]....

I am trying to Make A GUI which has a Jcombo box i also want it to have a jlabel that up dates depending on which option the user selects from the JcomboBox

for exampl if i select lion i want it to say you chose lion on the Jlabel and if i choose ostrich i want it to say ostrich and so on

View Replies View Related

JSF :: Updating View From AJAX

Sep 26, 2014

I have two images. I want to be able to click them and kick off a call to a listener in Java to change a value in the bean. I also want the view to update my dropdown (labeled "menuModel") to either be rendered or not, depending on which image I click. Alternatively, I would be fine with the dropdown simply being disabled and enabled for the same criteria.

So far, the listener kicks off fine, and the value gets updated correctly in the bean. However, the view never gets updated. I have tried this a hundred different ways, but nothing seems to work. If I hit refresh on my browser, the view updates. But I want it to do it automatically.

I am using standard JSF 2.1.

<div style="font-family: Verdana; font-size: 10pt; color: #FFFFFF">
<h2>Calibrations</h2>
<h:form id="tunerSelectionForm" style="color: #000000">
<h:commandLink>

[Code] .....

View Replies View Related

JComboBox Is Not Visually Updating

Jun 15, 2014

I have loaded the combo box at starting of program.When i am adding the element to combo box through database it's not updating visually.But the inserted data is successfully loaded in List.

void update_Attan() {
DefaultComboBoxModel nm = new DefaultComboBoxModel(new StudentMethods().update_combo_AttendanceType());
cmbStdAttType.setModel(nm);
}

View Replies View Related

Array Not Updating As A Heap?

Sep 25, 2014

When I add an element to my array, I have to make sure that it stays a heap, ie every child is smaller than its parent. However the method that I am using for this, trickling up, is not updating the elements properly, it pretty much just leaves is as is.

Here is the relevant code:

public class MaxIntHeap {
int[] array;
int actualSize = 0;
public MaxIntHeap(){
array = new int[20];

[code].....

View Replies View Related

Swing/AWT/SWT :: Why ProgressBar Not Updating

Aug 14, 2014

Why the Progress Bar is not Working in Second attempt?When i am Invoking Below Method on actionPerformed at first attempt its Working Fine but After that Its Not Working at all....

void initWait() {
go.setEnabled(false);
browse.setEnabled(false);
choice.setEnabled(false);
wait.setVisible(true);
wait.setMinimum(0);
wait.setMaximum(Info.getMp3().length);
System.out.println(Info.getMp3().length);
wait.setStringPainted(true);

[code]...

for a better Understand see this Mp3Arranger.jar or see the Whole Project SourceCode

View Replies View Related

Updating Time In Java

Oct 22, 2014

My program is working fine. When I executes it, it shows me this:

The clock is 54 minutes over 23 (+41 seconds.

and when i press ENTER, it shows me this:

23:54:41

But then it won't show me the update. I want to update the time, for example when I started the execution the time was 23:54:41 but it must show me something like 23:54:45, because I need the current time.

I have searched the whole internet about this but I don't know how to use the "Date.update ();".

Here is my code

package p2;

import java.util.Calendar;
import java.util.Date;
import javax.swing.JOptionPane;
public class Time {
public void myTime() {
Calendar cal = Calendar.getInstance();

[Code] ....

View Replies View Related

JSF :: Application Scoped Data Updating

Feb 18, 2015

I have an application scoped and i want to edit it from request scoped data. I use this code but application scoped data are not updating. What i am doing wrong?

Application Scoped Data

@ManagedBean
@ApplicationScoped
public class ApplicationData {
protected String contactEmail;
public String getContactEmail() {
return contactEmail;

[Code] ....

View Replies View Related

New Instance Variable Values Not Updating

May 6, 2015

Alright, I have a JavaFX gui that is creating a new instance of data calculation to graph in a chart; however, the data is not updating each time the Platform.runLater() feature executes. Each time an event occurs, a new instance with the same variable name occurs. I use to get methods to retrieve the data I want, so shouldn't the values update each time the new instance is created? This is a very condensed version of what happens with the event, but this is what is not working correctly.

Event:
solarPlot = new SolarTracker();
solarPlot.getElevation();
solarPlot.getAzimuth();
Class constructor :
public SolarTracker() {

[Code] .....

View Replies View Related

Game Over Method Not Updating Correctly

Sep 4, 2014

If I run this code. I can manipulate it so that X wins. When the third X button is pressed, there is no display saying that X has won and that the game is over. I have read over this code for days and still have not figured it out.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 public class TicTacToe extends JFrame implements ActionListener, WindowListener{
 public JFrame window = new JFrame("window");

[Code] ....

View Replies View Related

Tree Not Updating Values Properly

Aug 20, 2014

I am trying to create a tree that is like a take on 21 Questions. The tree pretty much just starts with three default values: the root/first question "Is it a mammal?", a left child "is it: human?", and a right child "is it: fish?", and then it builds off from there. It goes left for YES and right for NO. If the program guesses the wrong animal the user must enter the correct answer and a question that will distinguish the correct answer and the failed answer. That new question then becomes both the the failed answer and new answers's parent.

A little visual:

....................Is it a mammal?

...........It is: human?........Is it: fish?

*lets say it is a mammal but not human, ie a dog

Updated tree:

.....................Is it a mammal?

.....Does it have a tail?............Is it: fish?

Is it: dog?......Is it: human?

My problem is that after I update the tree 3rd time the values do not change properly. Lets say it is a mammal and its does have a tail, BUT its a cat, then, the updated question, which would now go before "is it: dog?" would be something like: "does it chase rodents?", which its left child would be cat and right would be dog.

However, when my program displays the values it would go something like this:

//first run: GOOD
Think of an animal and I will guess it!
Is it a mammal? Enter yes or no:
yes
Is it: human?
no

[Code] .....

So pretty much I can't understand what I'm doing wrong since the values in the print statements are right, but they are wrong during the actual run. Where is my error?

View Replies View Related

Updating Limits For Random Int Values?

May 4, 2014

Write a subclass of BasicGame in which the computer asks the user to choose a whole number from 1 to 100, inclusive. The program then makes a number of guesses. After each guess, the user tells whether the guess is too high, too low, or exactly right. Once the computer "knows" what the correct number is, the computer tells the user the correct number and the number of guesses tried. Have the program ask the user after each game whether she wants to play again. Design the program so that it always guesses the correct answer by the seventh try at latest. Hint: Have two instance variables that keep track of the smallest and largest values that the guess could be (initially 1 and 100). After each wrong guess, update these smallest and largest values appropriately.This is what I have written for the assignment:

Java Code:

import javax.swing.JOptionPane;
public class GuessThatNumber extends BasicGame
{
private java.util.Random randy;
private int itsCompNumber;
private int itsHigh = 99;
private int itsLow = 1;

[code]...

The part I'm having trouble with is changing the high and low values based on the input of "too high" or "too low," which I tried in the continueGame method... When I test the game, the values for itsCompNumber aren't restricted by the user's input at all, and I'm not sure how to fix it.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved