Swing/AWT/SWT :: Making A Tetris Clone - How To Get Cube To Visualize In JPanel

Nov 10, 2014

My question is, how do I get my Cube to visualize in the JPanel? I've tried a bunch of add methods but they don't compile. Is there a proper method I can use to add an object to a JPanel?

import javax.swing.*;
import java.awt.Dimension;
import javax.swing.Timer;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.*;

[Code] ....

View Replies


ADVERTISEMENT

How To Visualize Values Of The Selected Row

Nov 30, 2014

I'm currently writing a small program, where I need to save data into a Defaulttablemodel in a jTable.I have to save the name, a number and the email-adress.I added a button which opens a new JFrame and there I need to change the email and/or the name.My current solution is far from good: No matter which row I select, i can only update the "newest" row (last created). How can I visualize the values of the selected row (out.println// or whatever) so I can go further and overwrite these values.My Code when I click on Update:

int zeilenwahl = jTableStudenttab.getSelectedRow();
// System.out.println(jTableStudenttab.getSelectedRow());
if (zeilenwahl != -1) {
this.setVisible(false);
new Bearbeitung().setVisible(true);
} else {
JOptionPane.showMessageDialog(rootPane, "Zum Bearbeiten Zeile auswählen");
}

Here is where the mistake is (probably)

public Bearbeitung() {

initComponents();
jTextFieldvorname.setText(Student.vorname);
jTextFieldnachname.setText(Student.nachname);
matrikelstring = matrikelstring.valueOf(Student.matrikelnummer);
jLabelmatrikelwert.setText(matrikelstring);
jTextFieldemail.setText(Student.email);

}

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

Developing Tetris Based Characters - Can't Print The Piece Within Board

Dec 18, 2014

I post the code I'm developing for a tetris-based characters. The problem I have is that I can't print the piece within the board. I haven't any error.

Class Piezas

Java Code:

public class Piezas {

public Piezas() {}
//atributos
private int i;
private int j;
private char m[][];
private int formaPieza;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: AffineTransform Making Image To Move

Aug 5, 2009

I've been trying to make an image rotate in a panel. I did it. But also i want the image to make a translation.

Here is the code i tryed at paintComponent() :

//////////////////////////

Graphics2D g2 = (Graphics2D) g ;
AffineTransform at = new AffineTransform() ;
// at.rotate ( angle in radians ) ;
at.rotate( this.getAngulo(1, 1) ) ;
g2.drawImage(imgemFlecha, at, this);
/////////////////////////////

I cant change image x,y doing this drawImage(). I want to make that change.

View Replies View Related

Swing/AWT/SWT :: Alternative To Making Static JList?

Sep 16, 2014

I am currently writing a chess application in Java swing. For the GUI part, I have one MainWindow class, and one ChessBoard class. The MainWindow has a main panel, in which is contained 1) a panel containing the chessboard from the chessboard class (a grid layout array of 64 JLabels), 2) a JLabel status bar, and 3) a JList to hold the moves of the game. I have a movePiece method in the chessboard class, which I would like to add the move and question to the moves list, which is contained in the main window class.

However, since JList is some special type, I can't make it static ( that gives me an error ). I also tried creating a method in the main window class to add a move to the list, which I would then access via the chessboard class. However, I can't make the method static, because it is referencing a non-static variable ( the JList ), and since the Main window class already has an object of the chessboard class, trying to create a main window object in the chessboard class creates a stack overflow error.

View Replies View Related

Swing/AWT/SWT :: Making GUI Application Design Extensible

May 5, 2015

I have to create a Swing application for which i haved a set of requirements as,

1. there will be two JPanels ,left and right, on the main JFrame , left frame would contain a JTextField and a submit JButton ,user can enter values 1,2,3 ,in the JTextField and presses the JButton

a. if user enters 1, a JTextField will be shown on right JPanel
b. if user enters 2, a JTextField and a JRadioButton will be shown on right JPanel
c. if user enters 3, a JTextField and a JComboBox will be shown on right JPanel

So I have done that but when my boss sees the code behind this application he told me to make it more extensible i.e. if there is going to be an additional requirement for values 4 or 5 or 6 and so on , then i have to make minimal changes in my code or no change in my code and it should work . how this can be done ? is it possible make such software design ?

public class DesktopApp extends JFrame {
private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(DesktopApp.class);
private JPanel jp, jp2, mainPanel;
private JLabel jl, jl1, jl2, jl3, jl4, jl5;
private JTextField jText, jText2, jText3, jText4;

[Code] ....

What wrong am i doing here in this code which in not considered to be an extensible design ?

View Replies View Related

Swing/AWT/SWT :: Making Ball Bounce Around A Screen

Aug 12, 2014

I've got to make a ball bounce around a screen.... From what I can gather they seem to hold back useful java code.

anyway, i've changed the code over and over, and think this is the most succinct way i can manage it. but i have a problem. where i've marked the code (*****) and the following line are conditional on each other. so one won't provide the correct answer without the other line executing first, and vice versa (ignore the code after, i haven't looked at where that should be yet ). Anyway I don't really want to rip the code apart, again, because i'm pretty sure it's close.

View Replies View Related

Swing/AWT/SWT :: Making Interface - Exception Group Layout

Sep 24, 2014

I am making an expert system using Jess about animals. I wanted to make an interface using Swing and so I did. I have a problem using group layouts. The application works fine but at the end a exceptions is thrown:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,
alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,
preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,
horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,
text=The animal is a cheetah.,verticalAlignment=CENTER,
verticalTextPosition=CENTER] is not attached to a horizontal group

[Code] ....

The application ask the user some questions about the animal. When the expert system has enough information to know the animal it tells the name of the animal and shows a picture of it. The exception is thrown when the application has guessed the animal and shows the response.

Here is the code:

package xindria;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.GroupLayout.SequentialGroup;
import java.awt.*;
import java.awt.event.ActionEvent;

[Code] .....

I think the problem is related to the group layouts. I will attach the eclipse project too...

View Replies View Related

How To Clone Jar File By Itself

Mar 26, 2015

i need to design an application by java that is capable of coping itself and put it somewhere else.

and i have tried ....

import java.io.*;
import java.nio.*;
public class Test1234{

[Code]....

but it just create an empty folder named "test.class" but i need the overall class file or jar file.

View Replies View Related

Swing/AWT/SWT :: Making A Custom Cell Renderer Work In A JTable?

Jan 24, 2014

Now my issue is I have a JTable. The first column will contain Date objects all the way to the bottom. I want the JTable to display only the month and year. I created a custom cell renderer, but it appears the cell renderer method "getTableCellRendererComponent" is never called. (I tested it using System.out.println();) Here is my code for setting the cell renderer and the contents of the first column:

MonthYearTableCellRenderer renderer = new MonthYearTableCellRenderer();
tblView.setDefaultRenderer(Date.class, renderer);
for(int i = 0; i < 60; i++){
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.add(Calendar.MONTH, i);
tableModel.setValueAt(cal.getTime(), i, 0);
}

The Date objects are set into the cells of column 0 correctly. The table shows the result of the "toString()" method for each cell in that column.

View Replies View Related

Swing/AWT/SWT :: Making Two JComboboxes To Be In Sync When One Selects Item From Dropdownlist?

Jan 17, 2015

basically I would like to know how to to the following Java. Example... Say I have one JComboBox, and it is populated with 10 items which reads from a text file ("apple","banana","kiwi","orange","grape fruit"), and the other JComboBox holds the price ($1,$2,$4, etc etc...you get the drift).

How do I make in such a way when I select for example banana from the JCombobox that it syncs the other JCombox to the correct price?

Basically syncing the two JCombobox so that you do not need to select the price yourself - it does it automatically for you.

View Replies View Related

Swing/AWT/SWT :: JInternalFrame Over JPanel

Oct 3, 2014

I would like to know the possible ways to put up JInternalFrame over JPanel to achieve the following output.

Is it even Possible because i learned JInternalFrame can only be added to JDesktopPane.?

View Replies View Related

How To Clone ArrayList Objects

Jun 20, 2014

I want to clone some Arraylist, but the compiler apparently are just referencing the values to it's original ArrayList. I don't know what should it be:

package projetoteste;
import java.util.ArrayList;
import java.util.List;
public class TestFood {
public static void main(String[] args) {
List food=new ArrayList();

[code]....

Notice that ArrayList dailyMeal should be untouchable, but it return the changes that I made in local for-loop iteration although I didn't added nothing to it, just to it's clone.

Output:

[[[Suco, 1 , 2], [Suco, 1 , 2]], [[Suco, 1 , 2], [Suco, 1 , 2]]]
[[[►, ►, Suco, 1 , 2], [►, ►, Suco, 1 , 2]], [[►, ►, Suco, 1 , 2], [►, ►, Suco, 1 , 2]]]

View Replies View Related

Override The Clone Method?

May 14, 2014

the clone method of the object class is protected, so therefore we have to override this method I understand this. What doesn't make sense to me is that the protected access modifier gives access to classes in the same package and subclasses. Isn't every single class we make a subclass of the Object Class?

View Replies View Related

Swing/AWT/SWT :: Making JButton That Switches Text From 2 JTextFields On Click With Mouse

Aug 6, 2014

I have made a window using JFrame and on my JPanel I have added 3 components: 2 JTextFields ("field1" and "field2") and inbetween them a JButton ("switch"). My goal is to switch the value of field1 to field2 and vice versa when the JButton is clicked. I thought this ActionListener which I have added to my JButton would achieve my goal:

public void actionPerformed(ActionEvent e) {
field2.setText(field1.getText());
field1.setText(field2.getText());
}

However, it changes the value of field2 into the value of field1 but not the other way around.

View Replies View Related

Swing/AWT/SWT :: Image Not Being Displayed In Jpanel

Feb 19, 2014

Trying to get an image to display in a GUI.

try {
ByteArrayInputStream in = new ByteArrayInputStream(
transferWorker.bOutput
.toByteArray());
BufferedImage bufferedImage = ImageIO
.read(in);

[Code] ....

But nothing is happening in the GUI. I have stepped through and bufferedimage contains the data, but its not being displayed. Whats happening is, an image is being transmitted to serial port of laptop, so i'm taking it in and storing it in a BufferOutputStream and then trying to open it in my GUI class.

View Replies View Related

Swing/AWT/SWT :: JPanel Inside A Jframe?

Apr 9, 2014

I have a Jframe and i want to add inside 4 different jpanel.This is easy.

what is difficult is how can i change them dynamically with 4 other new jpanels and 4 other new jpanels?

I have try with BorderLayout but not working.

It's a wizard like but not the same.

I have a jpanel with jbuttons jpanel with a jtable jpanel with textarea and jpanel with jlabels. All this have to change with other 4 jpanels, where to look?

View Replies View Related

Swing/AWT/SWT :: How To Call PaintComponent In JPanel

Nov 7, 2014

How can I make a call to paintComponent within the JPanel-class, from another Class?

In class TestClass:

public class TestClass {
public TestClass() {
JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setSize(500,500);
initComponents();

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Scrollable JPanel Using MigLayout

Dec 28, 2014

I have been trying to create a chat client which makes use of a scrollable jpanel and at runtime adds JTextFields to the panel.

Panel Initialising

msgPanel = new JPanel(new MigLayout());
msgPanel.setPreferredSize(new Dimension(400,335));
JScrollPane msgPanelScroll = new JScrollPane(msgPanel);
msgPanelScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
msgPanelScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
mainPanel.add(msgPanelScroll,"span 3,alignx center,wrap");

[Code] .....

But now Im facing the following issues. The text field aligns to the center of the panel & on adding more fields the panel accommodates as it can and does not begin scrolling.

Screenshots attatched

View Replies View Related

Swing/AWT/SWT :: Why Jpanel Is Not Inserted In Jframe

Apr 4, 2014

I pick this code from Head first Java

package GUI;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Graphics;
import java.awt.Color;
public class gui5 {
int x=0;
int y=0;
public static void main(String... x) {

[code]...

but just a Jframe is appearing no Jpanel no green color circle?What is wrong with code

View Replies View Related

Swing/AWT/SWT :: Cannot Instantiate JPanel And Add It To JFrame

Mar 27, 2014

I am try to do an application based in multiples JFrames, each one with its particular responsibilities, and use one JPanel as a menu with buttons that connect one JFrame to another, But this menu is instantiated at run in view (layout made by netbeans) the Main Jframe appears with its internal JPanel, but the instantiated JPanel does not appear or does not show it's buttons. (notice only run method in the second class):

JPanel Menu that will be used in all alone JFrames of application:

public class MenuSuperior extends javax.swing.JPanel {
public MenuSuperior() {
initComponents();
} private void initComponents() {

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Disabling JPanel And All Its Components?

Oct 8, 2001

Let me explain by simplifying the GUI to a simple frame in which I have a JCheckbox and a JPanel mypanel.mypanel has a Textfield tf,JComboBox cmb as it's components.So now if I deselect the JCheckbox, all the components in the mypanel should be disabled. I used a code like:

[code]mycheckbox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if(mycheckbox.isSelected())
mypanel.setEnabled(true); else
mypanel.setEnabled(false); } });[code]

but the components inside the panels are not disabled. In my actual program I have a large number of different kinds of components in mypanel.So disabling/enabling each of them on each actionPerformed of the mycheckbox will be laborious. Isn't there any way by which I can disable/enable the mypanel to disable/enable all the components in it?

View Replies View Related

Swing/AWT/SWT :: JPanel In JFrame - Components Do Not Appear

Apr 4, 2014

I trying to replace original (and empty) JPanel in JFrame with my own made one, components does no appear right, when I pass the mouse first button appears:

MainViewClass:
...
private void initComponents() {
...
MenujPanel = new MenuSuperior();
MenujPanel.setBorder(
BorderFactory.createTitledBorder("Dados Pessoais"));

[Code] .....

Here is the video:

View Replies View Related

Swing/AWT/SWT :: JLists Are Not Appearing In JPanel

Apr 12, 2015

I need to add 2 JLists inside a JPanel for a crossword. The JPanel is located SOUTH and I'm using BorderLayout in the constructor to locate the JPanel.

The problem is, I can't see the 2 JLists inside the JPanel. For some strange reason the JLists appear in the center where the crosswordPanel is, even though the clues JPanel method is located SOUTH.

package crossword;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;

[code]....

View Replies View Related

Swing/AWT/SWT :: Putting Button In JPanel

Jul 3, 2014

I am trying to add buttons in a loop to my but when i compile my program i can`t see my buttons. I can see other stuff that added to jpanel ...

static JButton blocks[][];
for (int i = 0; i < block.length; i++) {
for (int j = 0; j < block[i].length; j++) {
block[i][j] = new Block(i, j);
blocks[i][j] = new JButton(i+"");
blocks[i][j].setLayout(new GridLayout((i+1) * 10, (i+1) * 10, 10, 10));
pageAxisPanel.add(blocks[i][j]);
}
}

View Replies View Related







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