awt

Can anyone help me identify the Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException on Line 65?

回眸只為那壹抹淺笑 提交于 2019-12-02 10:43:14
I keep getting a Run Time error that says I am having an Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException it is saying a [line 65] but to me it just looks like a basic if statement. I can give some background. this frame is call from a sequence of frames that is then once the state is selected sent to a new frame that contains states A-C cities. This current frame will work only when Alabama is not the state selected. (I have not created the other frames for the other states hence why they are commented out) I can put up the code to the other frame it is supposed to call

Class is not abstract and does not override abstract method AWT Program

五迷三道 提交于 2019-12-02 10:10:29
import java.awt.*; import java.awt.event.*; public class QuadraticSolver extends Frame implements ActionListener, WindowListener { private TextField tfX2; private TextField tfX; private TextField tfNum; private TextField tfVal1; private TextField tfVal2; private TextField tfRoots; private Label lblX2; private Label lblX; private Label lblNum; private Label lblVal1; private Label lblVal2; private Label lblRoots; private Button btnCheckRoots; private Button btnCalc; private Button btnClear; double a = 0, b = 0, c = 0; double Val1 = 0, Val2 = 0, Discriminant = 0; String StrVal1, StrVal2; public

Post overriding the paint method of the components in java

a 夏天 提交于 2019-12-02 10:08:44
In java awt or swing when you want to change painting of some component you usually have to override the method paint(Graphics g) (in awt) or paintComponent(Graphics g) (in swing). This is usually (maybe allways - I'm not sure) done when you are creating the component for example: JPanel jPanel = new JPanel() { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; //... my implementation of paint, some transfromations, rotation, etc } }; Imagine that you have container of components which could for example consists of some JLabels, some

Embedding a JFrame in an Applet

梦想与她 提交于 2019-12-02 09:48:26
I have found an open source application that creates a JFrame to display some content. I would like to "embed" this JFrame into an applet, so everything that is displayed in the Jframe will be displayed in the applet - is this possible? Thanks for your help! Create an instance of the frame. Get the content pane of the frame. Add the content pane to the applet. Andrew Thompson ..open source application that creates a JFrame.. Since the source is available, take whatever they do in the frame, and do that instead in an applet (with some slight variants & gotchas). Some typical problems with using

Adding a border to an image in Java

流过昼夜 提交于 2019-12-02 09:34:56
问题 I am trying to create an image that adds a border to an existing image on Java by copying the pixels from their old locations to new coordinates. So far, this is what I have done: public static NewPic border (NewPic p, int borderWidth, Pixel borderColor) { int w = p.getWidth(); int h = p.getHeight(); Pixel src[][] = p.getBitmap(); Pixel tgt[][] = new Pixel[h][w]; for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { tgt[y][x + y + borderWidth] = src[x][y]; // this is probably where I a

LibGDX - Conditionally use java or android classes

穿精又带淫゛_ 提交于 2019-12-02 09:28:47
I'm using bezier curves in my libgdx project. I was testing the desktop version using java.awt.geom with GeneralPath but when I went to test on android, it raised an error saying that I can't import java.awt . Android have corresponding classes for GeneralPath , Point2D etc so my question is how can I use those classes in their respective environments? Android does not have an AWT implementation, so references to those classes won't work on Android. (On the desktop you're getting those classes from the JDK.) Technically, you can put code that depends on AWT in your desktop Libgdx backend, and

assign keys for combo box in java

家住魔仙堡 提交于 2019-12-02 09:26:50
I want to add a JComboBox in Swing that is simple but I want to assign the values for each items in combo. I have the following code JComboBox jc1= new JComboBox(); jc1.addItem("a"); jc1.addItem("b"); jc1.addItem("c"); Now what I want is that when click on combo box it should return 1, 2 and 3 correspondingly instead of a ,b, c. Is there any way to assign the key values for each items in combo box? You can add an item as an object instead of adding String like this: JComboBox<ItemClass> jc = new JComboBox<ItemClass>(); jc.addItem(item1); jc.addItem(item2); jc.addItem(item3); So to return key,

AlphaComposite.CLEAR not working

断了今生、忘了曾经 提交于 2019-12-02 09:02:55
I have two JPanels on a JLayeredpane. One of them displays a pdf and the overlapping one has a transparent background (I have used setOpaque(false)). Now I can add drawings to the transparent panel such that it seems I'm actually annotating the pdf. I want to have a eraser tool to erase these annotations. I tried using the following code @Override public void draw(Graphics2D g2) { g2.setPaint(Color.WHITE); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR)); g2.setBackground(new Color(255, 255, 255, 0)); g2.setStroke(new BasicStroke(thickness, BasicStroke.CAP_ROUND, BasicStroke

NullPointerException on Java graphics

坚强是说给别人听的谎言 提交于 2019-12-02 09:01:38
问题 I'm trying to implement a method to paint a specific portion of a grid. To do so I overrided the paintComponent method: public class Frame extends JPanel { ... @Override public void paintComponent( Graphics g ) { super.paintComponent( g ); g.clearRect(0, 0, getWidth(), getHeight()); this.rectWidth = getWidth() / this.NUM_COLUMNS; this.rectHeight = getHeight() / this.NUM_ROWS; for (int i = 0; i < NUM_ROWS; i++) { for (int j = 0; j < NUM_COLUMNS; j++) { int x = i * this.rectWidth; int y = j *

Drawing Canvas on JFrame

柔情痞子 提交于 2019-12-02 08:50:14
I'm trying to draw simple shapes with Canvas, in this class I've set the painting public class Game extends Canvas{ //FIELDS public int WIDTH = 1024; public int HEIGHT = WIDTH / 16 * 9; //METHODS public void start(){ Dimension size = new Dimension (WIDTH, HEIGHT); setPreferredSize(size); paint(null); } public void paint(Graphics g){ g.setColor(Color.GREEN); g.fillRect(0, 0, WIDTH, HEIGHT); g.setColor(Color.BLACK); g.fillOval(100, 100, 30, 30); } } And in this the Window public class MainW { public static void main(String[] args) { Game ga = new Game(); JFrame frame = new JFrame (); frame