首页 \ 问答 \ 在简单的Java程序中从JButton打开一个URL?(Opening a URL from a JButton in simple Java Program?)

在简单的Java程序中从JButton打开一个URL?(Opening a URL from a JButton in simple Java Program?)

你好社区:),所以我是一个真正的Java新手,对吧? 我似乎无法获得从我的LINK GUI打开的URL。 目前,它只显示字段值。

这是我的handler.java代码:

google = new JButton("Google");
google.setToolTipText("Open Google");
add(google);

我希望它打开一个URL而不是显示字段值。 这是我的actionlistener代码:

    private class HandlerClass implements ActionListener {

    public void actionPerformed(ActionEvent event) {

        JOptionPane.showMessageDialog(null, String.format("%s", event.getActionCommand()));

    }

}

如果可能,我可以得到一些帮助吗? :) 谢谢


Hello there community :), So I'm a real java newb, right? I can't seem to get a URL to open from my LINK GUI. At the moment, it just shows the fields value.

Here is my handler.java code:

google = new JButton("Google");
google.setToolTipText("Open Google");
add(google);

I want it to open a URL instead of showing the fields value. This is my actionlistener code:

    private class HandlerClass implements ActionListener {

    public void actionPerformed(ActionEvent event) {

        JOptionPane.showMessageDialog(null, String.format("%s", event.getActionCommand()));

    }

}

If this is possible, can I get some assistance? :) Thanks


原文:https://stackoverflow.com/questions/10037644
更新时间:2023-09-07 14:09

最满意答案

好的,我想我已经整理出来了。 设置渲染模式的地方似乎是包含您的GLSurfaceView对象的类,而不是GLSurfaceView构造函数。 另外(我认为我在GLSurfaceView的Android文档中忽略了一些 ),在设置渲染器之前,您无法设置GLSurfaceView的渲染模式。 这也许就是为什么试图在构造函数中设置渲染模式不起作用的原因。

这似乎迫使它只在我想要的时候渲染,这正是我想要的:

public class Game extends Activity {
private GLSurfaceView glSurface;
private SurfaceViewClass svc;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    glSurface = (GLSurfaceView) findViewById(R.id.SurfaceView01);

    svc = new SurfaceViewClass(this);
    glSurface.setRenderer(svc);
    glSurface.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}

public void movePlayer() {
    svc.highlightSpot(location[PLAYER], 0);
    glSurface.requestRender();
}
}

OK, I think I got this sorted out. The place to set the render mode seems to be the class that contains your GLSurfaceView object, not in the GLSurfaceView constructor. Also (something I think I overlooked in the Android documentation for GLSurfaceView) you can't set the render mode of the GLSurfaceView before you set its renderer. This is perhaps why attempting to set the render mode in the constructor does not work.

This seems to force it to render only when I want it to, which is exactly what I wanted:

public class Game extends Activity {
private GLSurfaceView glSurface;
private SurfaceViewClass svc;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    glSurface = (GLSurfaceView) findViewById(R.id.SurfaceView01);

    svc = new SurfaceViewClass(this);
    glSurface.setRenderer(svc);
    glSurface.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}

public void movePlayer() {
    svc.highlightSpot(location[PLAYER], 0);
    glSurface.requestRender();
}
}

相关问答

更多
  • 你的surfaceview硬件是否加速了(我认为前3.0版本没有加速)? 如果是这样,那么它可能不会太不同。 如果它不是硬件加速,它可能会产生巨大的差异。 如果您确实使用OpenGL,请尝试使用DrawTexfOES函数,我相信这是根据Google IO演示文稿渲染纹理四边形的最快方法。 Is your surfaceview hardware accelerated (I think pre 3.0 they are not)? If so, then it probably won't be too d ...
  • 好的,我想我已经整理出来了。 设置渲染模式的地方似乎是包含您的GLSurfaceView对象的类,而不是GLSurfaceView构造函数。 另外(我认为我在GLSurfaceView的Android文档中忽略了一些 ),在设置渲染器之前,您无法设置GLSurfaceView的渲染模式。 这也许就是为什么试图在构造函数中设置渲染模式不起作用的原因。 这似乎迫使它只在我想要的时候渲染,这正是我想要的: public class Game extends Activity { private GLSurface ...
  • onDrawFrame方法中存在太慢的内存甚至外部存储访问。 您正在创建着色器和纹理(这是问题的最小) 每次将数据复制到的位置都会创建一个新的位图 然后,最慢的部分,你甚至将它保存到外部目录中。 这些都是问题所在。 There is too much slow memory and even external storage access done in the onDrawFrame method. You are creating a shader and a texture (that's the l ...
  • 使用当前的API集,亮度采样仅在记录开始时完成。 所以AVCaptureTorchModeAuto不能按预期工作。 现在讨论问题中讨论的用例: 可能性1:使用后置摄像头进行亮度检测: 一旦火炬出现,对捕获的流的分析将无法分辨房间亮度的当前情况,因为火炬将导致化妆品亮度。 因此,为了获得真正的亮度值,必须要求及时切换开关,这在大多数情况下不是非常通用和方便的 。 获得亮度值以决定是否启用Torch。 - (void)captureOutput:(AVCaptureOutput *)captureOutput ...
  • 当从ShouldComponentUpdate方法返回false时,React不会运行渲染方法。 我通过添加console.log命令来确认它。 不过,Chrome的React扩展 - 高亮更新 - 仍然会抬高页眉。 其原因可能是Header是应用程序组件的子组件,并且自App的渲染方法运行以来,Header被加亮。 When returning false from the ShouldComponentUpdate method React does not run the render method. ...
  • 我已经发现了这个问题。 Android默认开始从屏幕左边缘显示图像。 由于我的图像比屏幕大,因此超出的部分从右侧离开屏幕。 解决方案是计算宽度或高度差,然后在左侧(宽度)或顶部(高度)添加边距 ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) getLayoutParams(); if (CallConstants.isFullScreenMode) { if (layoutParams ...
  • 您的问题已经有了答案,但我会详细说明一些链接。 Surface的大小与View的大小无关。 如果它们不同,则显示硬件会在Surface显示屏上显示时调整Surface的大小。 这意味着您可以使用setFixedSize()调用为Surface设置任意大小,这可用于减少Canvas或GLES必须更新的像素数。 如果您使用Canvas绘制软件,则可以避免重新缩放位图,因为可以依靠每个设备上的Surface大小相同。 有关于该功能的官方博客文章 ,以及它在Grafika中使用的一个例子( 视频在这里 )。 You ...
  • 通过将GLES20.glDepthFunc(GLES20.GL_LEQUAL)更改为GLES20.glDepthFunc(GLES20.GL_ALWAYS)来解决; Solved by changing GLES20.glDepthFunc( GLES20.GL_LEQUAL ) to GLES20.glDepthFunc( GLES20.GL_ALWAYS );
  • 我意识到这是一个非常古老的问题,但万一它可以帮助任何人: 根据IE8浏览器模式与文档模式的问题的答案 ,浏览器模式“只是”设置User-Agent字符串。 但是,由于在评估IE条件注释时使用此值,因此如果(a)任何代码直接针对UA字符串进行测试,或者(b)代码中存在IE条件注释,则浏览器模式可能会对渲染产生影响。 IE8 Compat的浏览器模式通常会评估为UIE字符串MSIE 7.0 ,因此,如果您有任何条件注释检查if lt IE8 ,例如,这可能是您的问题的根源。 I realise this is ...
  • 你不能。 API无法正常工作。 相反,使用if / then或switch语句的单个方法会导致它改变行为。 如果您不喜欢这种方法,请使用普通的SurfaceView并提供您自己的EGL设置和线程类。 然后你可以随心所欲地渲染,甚至可以利用Choreographer之类的东西来减少延迟。 有关示例,请参阅Grafika 。 You can't. The API doesn't work that way. Instead, use a single method with an if/then or swit ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。