paint

Java JFrame draw

两盒软妹~` 提交于 2019-12-25 12:09:14
问题 I'm currently working with JFrame and I'm trying to draw a rectangle but I don't know how to execute the code paint(Graphics g) , how do I get the Graphics object? package com.raggaer.frame; import java.awt.Dimension; import java.awt.Graphics; import javax.swing.JFrame; public class Frame { private JFrame frame; public Frame() { this.frame = new JFrame("Java Snake"); this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.frame.setSize(new Dimension(500, 500)); // DRAW?? this.frame

Java JFrame draw

邮差的信 提交于 2019-12-25 12:08:58
问题 I'm currently working with JFrame and I'm trying to draw a rectangle but I don't know how to execute the code paint(Graphics g) , how do I get the Graphics object? package com.raggaer.frame; import java.awt.Dimension; import java.awt.Graphics; import javax.swing.JFrame; public class Frame { private JFrame frame; public Frame() { this.frame = new JFrame("Java Snake"); this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.frame.setSize(new Dimension(500, 500)); // DRAW?? this.frame

How to rotate an ellipse around the center of program?

不想你离开。 提交于 2019-12-25 04:19:18
问题 So I used tutorials from http://zetcode.com/tutorials/javagamestutorial/basics/ and I'm using the Donut program. For anyone unfamiliar it does this http://zetcode.com/img/gfx/javagames/donut.png I want to make the ellipses rotate around the center of the window, to make it look like it's moving in a circle. The code so far is the code from the webpage. package donut; import javax.swing.*; import java.awt.*; import java.awt.geom.AffineTransform; import java.awt.geom.Ellipse2D; public class

C console repainting stuttering/not fluid

本秂侑毒 提交于 2019-12-25 03:14:33
问题 I am trying to make a simple snake game on console. I am using an int matrix to store all the data (borders, snake, food to eat) at their exact location. I use this main code for now to run the program : int main() { int tab[28][120]; create(tab, 28, 120); paint(tab, 28, 120); char i = '1'; char direction = 'R'; while(i != 'q') { if (kbhit()) i =getch(); translate(tab, direction, 28, 120); paint(tab, 28, 120); Sleep(300); } } The main problem being, every time I repaint the matrix, it

How to make JFrame paint only after I click button?

 ̄綄美尐妖づ 提交于 2019-12-25 01:51:30
问题 When I run the application the whole frame is painted black. How can I make it so that it starts out clear then it gets painted when I press the button? package card; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class BdayCard extends JFrame { JButton button1, button2; JPanel panel; BdayCard() { panel = new JPanel(); button1 = new JButton(); button1

JTable returning null for Graphics?

≡放荡痞女 提交于 2019-12-25 01:33:22
问题 I'm trying to draw lines over my JTable using a Painter object that I've made, but for some reason table.getGraphics() returns null. Painter class: import java.awt.BasicStroke; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JTable; public class Painter extends JTable { public Painter(){ } public void paintSudokuLines(Graphics g){ paintComponent(g); } public void paintComponent(Graphics g){ super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setStroke(new

How to make 2D graphic transition in android canvas

十年热恋 提交于 2019-12-24 18:21:58
问题 I have draw a circle using paint and canvas in android . I want to move the circle in some direction, are there any API methods that can be used ? Or do I have to use a loop and changing the position each time? 回答1: Hi you can refer the code below, In onTouchEvent, you can handle directions and move the object. // Tutorial2D.java main activity import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.view.Window; public class Tutorial2D extends

Changing stroke color changes previous strokes color

本小妞迷上赌 提交于 2019-12-24 16:28:52
问题 I'm trying to make an android kids coloring book app, and when I'm firstly drawing with one color its ok, but when I change the brush color, all the previous coloring changes color as well. What can be the solution of this problem? Starting to paint with one color: After changing the color and making another stroke this is what's happens Here is my SignatureView class that is for this drawing surface: public class SignatureView extends View { private float STROKE_WIDTH = 5; /** Need to track

Java/Swing offscreen rendering (Cobra HTMLPanel -> BufferedImage) Problem: Component doesn't finish redrawing first

馋奶兔 提交于 2019-12-24 16:27:49
问题 I'm trying to render the contents of a the Java/Swing Cobra HTML renderer to an offscreen BufferedImage, for use elsewhere in my app: slideViewPanel.setDocument(document, rendererContext); BufferedImage test = new BufferedImage(300,300,BufferedImage.TYPE_INT_RGB); Graphics g = test.getGraphics(); slideViewPanel.paint(g); The resulting image in g shows a partially rendered page -- sometimes the contents of the HTMLFrame before the new document was set; sometimes a half-rendered version of the

Applet not painting

旧巷老猫 提交于 2019-12-24 15:42:56
问题 I am having issues with my Applet not painting the required graphics. For some reason, it updates the coloring in the graphics, as you can see this when it prints, it recognizes the mouse is being moved, the graphics are not null, but it still refuses to paint. How can this be fixed? import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import javax.swing.JApplet; public class GameApplet extends JApplet implements