awt

MediaTracker - how to use it, what are the benefits, or is there an alterative?

爱⌒轻易说出口 提交于 2020-01-19 12:55:22
问题 In the codebase we inherited the usage of MediaTracker was always done locally in each code block. new MediaTracker(new Canvas()); mediatracker.addImage(i, 1); try { mediatracker.waitForAll(); } catch (InterruptedException e) { } mediatracker.removeImage(i); Deciding this was inefficient, I eventually replaced it with a static instance and method: final static protected MediaTracker mediatracker = new MediaTracker(new Canvas()); static protected void checkImageIsReady(Image i) { mediatracker

How to define multiple JButton actions from a different class

一曲冷凌霜 提交于 2020-01-18 04:33:04
问题 I am writing a program where I need to do different actions for a separate class depending on which button is clicked. public class NewJFrame{ public static JButton b1; public static JButton b2; public static JButton b3; } public class Slot{ int value; JButton button; Slot(int value, JButton button) { this.value=value; this.button=button; } } public class Game{ Slot[] slots=new Slot[3]; Game(){ slots[0]=new Slot(1,NewJFrame.b1); slots[1]=new Slot(2,NewJFrame.b2); slots[2]=new Slot(3,NewJFrame

How to define multiple JButton actions from a different class

孤街浪徒 提交于 2020-01-18 04:32:30
问题 I am writing a program where I need to do different actions for a separate class depending on which button is clicked. public class NewJFrame{ public static JButton b1; public static JButton b2; public static JButton b3; } public class Slot{ int value; JButton button; Slot(int value, JButton button) { this.value=value; this.button=button; } } public class Game{ Slot[] slots=new Slot[3]; Game(){ slots[0]=new Slot(1,NewJFrame.b1); slots[1]=new Slot(2,NewJFrame.b2); slots[2]=new Slot(3,NewJFrame

How to set divider location for JSplitPane on start-up

情到浓时终转凉″ 提交于 2020-01-17 08:06:29
问题 I have JPanel which contains JSplitPane. The JPanel is injected during a runtime into a JFrame using the method invokeAndWait. Then the invokeLater is called to update divider location in SplitPane. The problem is, when the divider update is invoked, JPanel width is still 0. When I add sleep or a breakpoint anywhere in the code (except the invokeLater), the code works fine. final JPanel viewPanel = new JPanel(); viewPanel.setLayout(new BorderLayout()); final JPanel header = getPresenterHeader

Using Font from my JAR

99封情书 提交于 2020-01-16 19:03:27
问题 I have added a font to my JAR file from eclipse and am trying to use the font within JTextFields. The setText isn't being drawn when I run the application, just a - in the JTextField. I based my code off Exporting font to jar in eclipse. Below is my code: //lets load the font Font font = Font.createFont(Font.TRUETYPE_FONT, Main.class.getClassLoader().getResourceAsStream("Coalition_v2.ttf")); font.deriveFont(Font.PLAIN, 14); txtBrain = new JTextField(); txtBrain.setFont(font); txtBrain.setText

Checkboxes not showing up

人走茶凉 提交于 2020-01-16 14:54:43
问题 I am hoping another set of eyes can help me find where my code is wrong. I can compile and run the program, but all I get is a white screen. It's supposed to show the checkboxes and change the background to whichever color is chosen. Any help is appreciated! import javax.swing.JOptionPane; import java.awt.*; import java.awt.event.*; public class Chapter5Debug extends Frame implements ItemListener { static Chapter5Debug f = new Chapter5Debug(); CheckboxGroup options = new CheckboxGroup();

Pass button click event to actionPerformed on key press

筅森魡賤 提交于 2020-01-15 11:54:20
问题 I'm working on a Java assignment that has to be done using AWT. I want a button to trigger by pushing the enter key while the button is in focus. I figured out how to do this in Swing with the doClick() method, but this doesn't seem to work in AWT. So far I'm trying this: button.addActionListener(this); // Passes value from a TextBox to actionPerformed() button.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if(e.getKeyCode()==KeyEvent.VK_ENTER) { actionPerformed(null);

Destroy instance of class then create instance of it again

纵饮孤独 提交于 2020-01-15 06:05:46
问题 i have a class (Class ButtonX) that contains a button when user clicks the button, it will create instance of the class DialogX when I create instance of the class DialogX it will show up JDialog public class ButtonX { public ButtonX() { JFrame me = new JFrame(); JButton n = new JButton("show dialog"); n.addActionListener(ListenerX.listen); me.getContentPane().add(n); me.pack(); me.setVisible(true); } public static void main (String[]args){ new ButtonX(); } } listener of that JButton public

Destroy instance of class then create instance of it again

こ雲淡風輕ζ 提交于 2020-01-15 06:03:12
问题 i have a class (Class ButtonX) that contains a button when user clicks the button, it will create instance of the class DialogX when I create instance of the class DialogX it will show up JDialog public class ButtonX { public ButtonX() { JFrame me = new JFrame(); JButton n = new JButton("show dialog"); n.addActionListener(ListenerX.listen); me.getContentPane().add(n); me.pack(); me.setVisible(true); } public static void main (String[]args){ new ButtonX(); } } listener of that JButton public

new font type in java

非 Y 不嫁゛ 提交于 2020-01-15 01:50:37
问题 In my job we have to use an specific font type, is Futura std medium. I have a JFrame where I write, and I need to do with this font type. I have the OTF document, but I cant find the way to import it in my code. 回答1: Did you try to check this answer about OTF in Java : How to use Custom Font in Java and Use OTF in Java I think it could help you. 来源: https://stackoverflow.com/questions/10430898/new-font-type-in-java