Tag: jframe

如何从另一个Java类调用JFrame

我正在尝试做一个简单的Jform并从另一个类调用它。 我想在服务器客户端应用程序中使用此Jframe,但我不知道如何从另一个类打开JFrame类。 喜欢用户必须选择 1-打开Jframe。 2-退出。 那我做错了什么? 以下是代码: Jframe类名为Calculas.java /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author user */ public class Calculas extends javax.swing.JFrame { /** * Creates new form Calculas */ public Calculas() { initComponents(); } /** * This method […]

将.swf文件嵌入我的Jframe

我将swf文件添加到我的jframe有问题。 他们说我应该尝试使用JFlash播放器但它只是一个试用版。 你能给我一些示例代码吗?

在Swing中指定Canvas的位置

我正在学习Swing GUI设计。 我还没有完全解决的一件事是如何添加一个Canvas添加到容器中的特定位置。 更具体地说:我创建了一个使用Paint方法的Canvas类。 此类的对象将添加到Panel中。 我不太明白的是,它是如何以及在何处添加到Panel中的。 在Tkinter中, Canvas是一个仅包含图像的小部件,但在Swing中,没有类似的小部件(可能不是最好的单词)添加到仅包含Canvas对象的Frame,而没有其他内容。 对不起,如果它太模糊,我正在添加一个自包含的代码。 请忽略文本字段和标签。 import java.awt.BorderLayout; import java.awt.Canvas; import java.awt.Color; import java.awt.Container; import java.awt.FlowLayout; 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.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JSeparator; import javax.swing.JTextField; //frame class class frame_class2 extends JFrame implements ActionListener{ //declare buttons JButton draw_button = new JButton(“Draw”); […]

奇怪的JFrame行为

我有以下程序,它运行时有一些非常奇怪和不需要的行为。 它应该有两个按钮,“开始”和“停止,但当我点击”开始“另一个按钮显示在”开始“的正下方。这是我正在谈论的打印屏幕: 我做错了什么,如何解决这个丑陋的问题? 这是代码: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.Random; public class TwoButtonsTest { JFrame frame; Timer timer; boolean isClicked; public static void main(String[] args) { TwoButtonsTest test = new TwoButtonsTest(); test.go(); } public void go() { frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(500, 500); JButton startButton = new JButton(“Start”); startButton.addActionListener(new StartListener()); JButton stopButton […]

Java JFrame背景颜色不起作用

我试过用: frame1.getContentPane().setBackground(Color.yellow); 但它没有用。 谁能帮我? import java.awt.*; import java.awt.Color; public class PlayGame { public static void main(String[] args) { GameFrame frame1 = new GameFrame(); frame1.getContentPane().setBackground(Color.yellow); // Set Icon Image icon = Toolkit.getDefaultToolkit().getImage(“image/poker_icon.gif”); frame1.setIconImage(icon); frame1.setVisible(true); frame1.setSize(600, 700); frame1.setTitle(“Card Game”); // Set to exit on close frame1.setDefaultCloseOperation(GameFrame.EXIT_ON_CLOSE); } } GameFrame import javax.swing.*; import java.awt.*; import java.awt.event.*; public class […]

背景图像JFrame与内容

我有一个带BorderLayout的JFrame ,四面都有面板(北,东,……)。 在面板中主要有标签和按钮。 现在我希望框架有一个背景图像,一些研究告诉我,我必须更改框架的内容窗格。 但是当我尝试这个时,内容会被放入后台并且不可见。 另外,如果调整帧大小,我不知道如何调整图像大小。 是否有一个简单的解决方案或我将不得不重做我的大部分代码?

java JFrame图形

我在JFrame构造函数中有以下简单代码 super(name); setBounds(0,0,1100,750); setLayout(null); setVisible(true); g = this.getGraphics(); int[] x =new int[]{65, 122, 77, 20, }; int[] y =new int[]{226, 258, 341, 310}; g.setColor(Color.RED); g.drawPolygon (x, y, x.length); System.out.println(g); 我在控制台上获得输出: sun.java2d.SunGraphics2D [字体= java.awt.Font中[家族=对话框,名称=对话框,风格=平原,大小= 12],颜色= java.awt.Color中[R = 255,G = 0,B = 0 ]] 但是在JFrame上没有绘制红色多边形,只有空白JFrame。 为什么?

在java中打印2页的jframe

我想打印一个包含大量文本字段和包含数据的按钮的jframe。 我想通过单击打印jbutton打印此jframe。 我试过这段代码。 protected void print() { PrinterJob job = PrinterJob.getPrinterJob(); if(job.printDialog()){ try { job.setPrintable(new Printable() { @Override public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { if(pageIndex == 0){ Graphics2D g2d = (Graphics2D)graphics; g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); Dimension dim = ODietListJFrame.this.getSize(); double cHeight = dim.getHeight(); double cWidth = dim.getWidth(); // get the bounds of […]

如何将ImageIcon添加到JFrame?

我正在尝试将图像添加到一个帧但看起来它不起作用。 ImageIcon从指定文件创建的图像。 图像文件位于java文件存在的seam目录中。 import java.awt.BorderLayout; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; public class image { public static void main(String args[]) { TimeFrame frame = new TimeFrame(); } } class TimeFrame extends JFrame { //Image icon = Toolkit.getDefaultToolkit().getImage(“me.jpg”); ImageIcon icon = new ImageIcon(“me.jpg”); JLabel label = new JLabel(icon); public TimeFrame(){ this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle(“My Frame”); setSize(500,400); //this.setIconImage(icon); add(label,BorderLayout.CENTER); […]

如何将jFrame设置为始终位于顶部并且在关闭之前启用焦点?

我的程序中有两个不同的框架,第二个框架在我点击jButton是第一个框架时打开,所以当第二个框架打开时,我希望第二个框架始终在顶部并聚焦直到它关闭。 在第二个窗口关闭之前,不允许用户在第一个窗口中执行任何操作。 我怎样才能做到这一点?