paint

Bug when drawing rectangles in my Paint Program

我的梦境 提交于 2019-12-02 09:46:38
public partial class Form1 : Form { Point downPoint , upPoint; List<Shapes> shapes = new List<Shapes>(); public ShapesEnum shapeType; public Form1() { InitializeComponent(); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); foreach (var s in shapes) s.Draw(e.Graphics); } protected override void OnMouseDown(MouseEventArgs e) { downPoint = e.Location; } protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); upPoint = e.Location; CreateShape(); this.Invalidate(); } private void CreateShape() { if (shapeType == ShapesEnum.Circle) { Rectangle rect = new

Dragging Image using MouseDrag method

半世苍凉 提交于 2019-12-02 09:34:16
I'm trying to code where an image can be dragged using the mouseDragged method, but I can't seem to successfully do it with my current code. My aim is to ensure that when I place drag on every image in the applet, it follows the cursor. /* Using drag mouseEvent, all objects in the app can be dragged... */ package finals_two; import java.applet.*; import java.awt.*; import java.awt.event.*; /* 10/16/2015 * @author michael.pabilona */ public class Finals_Two extends Applet implements MouseMotionListener { int hei, wid, xCoordinate, yCoordinate; Image leftReceiver1, leftReceiver2, leftReceiver3;

paintComponent is not being called in JPanel

和自甴很熟 提交于 2019-12-02 09:19:30
I have following code: package hra; import java.awt.Color; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.JFrame; import static javax.swing.JFrame.EXIT_ON_CLOSE; import javax.swing.JPanel; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class HerniPole extends JPanel implements KeyListener { public int velikostPole; HerniPole(int velikostPole) { this.velikostPole = velikostPole; Color background = new Color(187, 173, 163); EventQueue.invokeLater(new Runnable() {

Java full screen background color wont change?

百般思念 提交于 2019-12-02 09:07:56
问题 I have some code that creates a full screen icon in java and sets the background color to pink and the foreground color to red. However every time i run it, it never changes the background color to red but just keeps it see through. I put the code below. The main java: import java.awt.*; import javax.swing.*; @SuppressWarnings({ "serial" }) public class bob extends JFrame{ public static void main(String[] args) { DisplayMode dm = new DisplayMode(800,600,16, DisplayMode.REFRESH_RATE_UNKNOWN);

How to call a method that uses PaintEventArgs and coordinates variables

本小妞迷上赌 提交于 2019-12-02 08:31:56
I recently started programming in C# obviously and was trying to do a simple WinForms app that takes mouse coordinates and scales a Rectangle according to the coordinates. The issue I am facing is that i dont know how to call a method that uses more arguments (in this case is x, y and PaintEventArgs ). Or I do know, but I don't know what to do with the PaintEvent . Here is the whole code, since its pretty short and rather simple: using System; using System.Drawing; using System.Windows.Forms; public partial class Form1 : Form { public void Form1_MouseMove(object sender, MouseEventArgs e) { int

Overriding the paint() method

断了今生、忘了曾经 提交于 2019-12-02 07:58:40
I've got a beginner question here that I was hoping someone with some Java experience could help me with. Currently taking an intro to OOP course focused on Java. My instructor is currently covering awt and swing, specifically the need to override the paint method so that graphics are redrawn when a window is resized, etc. I like to do as much outside reading as possible, and my concern is that the examples that my professor gives involve things that I've read are not best practices. To get to the point... I understand that it's necessary to override the paint method, but I don't know the best

The point of origin in my GUI is off by about 25/26 pixels

梦想与她 提交于 2019-12-02 07:34:56
问题 My point of origin (0,0) on my GUI is moved up by about 25/26 pixels. So the very top-left corner of my GUI seems to represent 0,25 or 0,26. I am using a double buffer to draw in things. Basically, whenever I try to draw something in my buffer at 0,0, it appears off-screen. For example, below is a screenshot of a checkerboard pattern I attempted to generate, starting from 0,0. Although it seems fine horizontally, notice the chopped checkerboard at the top. The height is 480, which is

How to export one to one JTable in the pdf [duplicate]

♀尐吖头ヾ 提交于 2019-12-02 07:31:53
Possible Duplicate: Why does the JTable header not appear in the image? Drawing JTable rows and columns on a Panel I am working on a report application in which I have to export a JTable in the form of report. But when I try to directly paint JTable on the PDF, it doesn't show the 1st row and column border. For this I tried by using default color grid Left Top borders. Which gives me a darker line in the PDF. However when try to fill any particular cell with color and export it on PDF output, all the grid lines are invisible. SimpleTableDemo.java : package com.swing.table; import java.awt

Draw a line on ImageView set by Picasso

故事扮演 提交于 2019-12-02 07:25:32
I am trying to figure out how to simply draw a line on an image that is being set in Picasso. I found that if I simply set the image, given a URI, with Picasso and try to draw paint to it using the following: canvas = new Canvas(bitmap); image.draw(canvas); topEdge = new Paint(); topEdge.setColor(context.getResources().getColor(R.color.blue)); topEdge.setStrokeWidth(5); canvas.drawLine(c1.getX(), c1.getY(), c2.getX(), c2.getY(), topEdge); Then I get a crash saying that the bitmap needs to be mutable first. So I added this above that code: Bitmap workingBitmap = ((BitmapDrawable) image

Java Swing heavy/slow paintComponent - any advice?

不问归期 提交于 2019-12-02 06:18:40
I'm making a scrolling 2D map/tile based game. Each tile (stored as tile[21][11] - 231 tiles total per map) can contain up to 21 values (stored as int[3][7]). While full-screen I see about 8 maps at once. On average, each map takes about 0.03 seconds to draw (found with System.nanoTime). The problem is that as soon as more than 1 map is on the screen, the Swing event polling noticeably slows down. Is there any solution to this? I can't draw the map a single time to save it as an image because it has transparency involving moving actors, so it changes too frequently. Also I don't think I can