
这是我之前的问题的继续,我问如何在系统托盘中放置一些东西.
在社区的一些帮助下,我可以做到这一点.但是什么我不能做的是改变的文本JTextField中JWindow.
该JWindow有JPanel,一切都置于内JPanel,包括JTextField的提醒百万吨.但是,即使我无法输入任何内容setEditable(true).
的JTextField,因为它应该是白色的,当鼠标进入和返回时鼠标退出到默认的颜色正确地接收事件.
这有什么解决方法吗?
package demo;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.sound.sampled.*;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import example.Kernel32;
public class SSCCE {
JPopupMenu popup = new JPopupMenu();
JMenuItem exit = new JMenuItem("Exit");
JWindow window = new JWindow();
JPanel panel = new JPanel();
int remindMeAt = 55;
Kernel32.SYSTEM_POWER_STATUS batteryStatus = new Kernel32.SYSTEM_POWER_STATUS();
Clip buzzer;
AudioInputStream …Run Code Online (Sandbox Code Playgroud) 因此,在经过大量的努力之后,我才结束了.我的RemoteViews通知中有一个媒体播放器,我希望能够访问播放,暂停,上一个和下一个按钮.
我知道setOnClickPendingIntent()将用于通知通知.但是,我想知道它是如何工作的.
是否可以让服务处理点击?
我试过这个,但是徒劳无功.我试图让我服务处理播放器的暂停和恢复:
rm = new RemoteViews(getApplicationContext().getPackageName(), R.layout.notif_media_player);
Intent intent = new Intent(getApplicationContext(), MusicService.class);
intent.putExtra(REQUEST_CODE, PAUSE);
PendingIntent pending = PendingIntent.getService(getApplicationContext(), PAUSE, intent, 0);
rm.setPendingIntentTemplate(R.id.pause, pending);
Notification notif = new NotificationCompat.Builder(getApplicationContext())
.setOngoing(true)
.setSmallIcon(R.drawable.ic_launcher)
.setContent(rm)
.build();
NotificationManager mgr = (NotificationManager) getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
mgr.notify(NOTIFICATION_ID, notif);
Run Code Online (Sandbox Code Playgroud)
我的IBinder是空的.如果这有所作为.
如何从通知中暂停和播放音乐?
android android-service android-pendingintent android-remoteview
稍微有点noob-ish问题,但在计算手机密度桶的时候我感到很困惑.我将把我的Galaxy S3作为一个例子.
它的分辨率1280 x 720意味着它具有306 dpi.现在,参考下面的图表,我的手机属于该hdpi类别,因为它的屏幕数量240 dpi超过了320 dpi所需数量xhdpi.所以,手机是853 x 480 DP(除以1.5)
但是,我手机上的屏幕信息应用程序告诉我它是一个xhdpi屏幕.所以,手机是640 x 360 DP(除以2).
我怎么知道手机的密度桶是什么?
更新:
我正在尝试为我所在国家/地区的前10款Android手机设计我的应用.因此,我正在计算他们在DP中的大小,以根据他们的"最小宽度DP"设计UI.这不是一次性的大小计算.
public void run(){
Icon reel = common.ResourcesToAccess.reel;
JLabel label = new JLabel(reel);
JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.getContentPane().add(label);
frame.setSize(reel.getIconWidth(),reel.getIconHeight());
frame.setLocationRelativeTo(null);
frame.setVisible(true);
try{
sleep(2*1000);
}catch(InterruptedException e){
}
frame.dispose();
}
Run Code Online (Sandbox Code Playgroud)
我尝试键入reel.setImageObserver(label);但Eclipse将该语句标记为错误.为什么?
我还能做些什么来展示动画?
@Override
public void run(){
JFrame f = new JFrame();
ImageIcon reel = (ImageIcon) common.ResourcesToAccess.reel;
JLabel label = new JLabel(reel);
reel.setImageObserver(label);
f.getContentPane().add(label);
f.setUndecorated(true);
f.setSize(300, 300);
f.setVisible(true);
}
Run Code Online (Sandbox Code Playgroud)
虽然我可以在这里设置ImageObserver,但GIF仍然没有动画
我正在使用的GIF可以在这里找到:
http://bestanimations.com/Electronics/Video/Video.html
这是右边电视上方的那个.旋转卷轴.

对不起,如果标题含糊不清,但这正是我想要实现的.
这是Battery Care软件图标化/最小化.将鼠标悬停在图标上时,您将看到图片中显示的窗口.
如何在Java中实现?
所以我想JPopupMenu在用户单击系统托盘中的图标时显示.但是,任务栏可以位于屏幕上的任何位置 - 底部,顶部,右侧,左侧.

如何确定sys托盘的位置以便显示弹出窗口?
getX()并getY()可以获得点击的坐标.可以做一些数学运算来正确显示弹出窗口吗?
一个简单的解释和示例代码将不胜感激.
此外,如果任务栏被隐藏,当我添加TrayIcon到SystemTray?时会生成异常吗?
我试图通过使用DOM验证器在Java中使用XSD验证我的XML.
虽然我手动地知道该文档确实有效,但DOM验证器还是对我说:
cvc-complex-type.3.2.2: Attribute <xsi:schemaLocation> is not allowed to appear in the element <people>
Run Code Online (Sandbox Code Playgroud)
我已经确定的是:
setNamespaceAware()被设置为true
的schemaLanguage是之前设置属性schemaSource
schemaLanguage设置为http://ww.w3.org/2001/XMLSchema
两者的XSD和XML在同一个文件夹中.java和.class文件
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import javax.xml.parsers.*;
public class DOMValidator {
String xmlInstance = null;
String xmlSchema = null;
public static void main(String[] args){
DOMValidator validator = new DOMValidator();
validator.validateXML("student.xsd",
"helloWorld.xml");
}
public void validateXML(String xsd,String xml){
xmlSchema = xsd;
xmlInstance = xml;
beginValidation();
}
public …Run Code Online (Sandbox Code Playgroud) [2013-07-21 11:14:01 - AndroidTrial] Installation failed due to invalid URI!
[2013-07-21 11:14:01 - AndroidTrial] Please check logcat output for more details.
[2013-07-21 11:14:02 - AndroidTrial] Launch canceled!
Run Code Online (Sandbox Code Playgroud)
这是我尝试运行试验项目时得到的结果.logcat中没有输出.
我在SO上查看了其他类似问题的答案,他们说这可能是因为重音字符.我没有这些.
这是我的简单代码:
public class HaikuDisplay extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onTrialButtonClicked(View view){
TextView v = (TextView) findViewById(R.id.text);
v.setVisibility(View.VISIBLE);
}
}
Run Code Online (Sandbox Code Playgroud)
这是XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".HaikuDisplay" >
<Button
android:id="@+id/topBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/love_button_text"
android:onClick="onTrialButtonClicked"
/>
<TextView
android:layout_below="@id/topBtn"
android:id="@+id/text"
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) 我正在查看ThreadPoolExecutor该类,我发现它允许指定最大池大小和核心池大小.
我有点了解何时根据这里的答案更改核心和最大池大小:何时在ThreadPoolExecutor中指定单独的核心和最大池大小是一个好主意?
但是,我想知道这些"核心线程"是什么.当我使用a的getCorePoolSize()方法时,我总是得到0ThreadPoolExecutor
SSCCE在这里:
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
public class PoolSize {
public static void main(String[] args) {
// Create a cached thread pool
ExecutorService cachedPool = Executors.newCachedThreadPool();
// Cast the object to its class type
ThreadPoolExecutor pool = (ThreadPoolExecutor) cachedPool;
// Create a Callable object of anonymous class
Callable<String> aCallable = new Callable<String>(){
String result = "Callable done !";
@Override
public String call() throws Exception {
// …Run Code Online (Sandbox Code Playgroud) {
"title" : "That Uselessly Amazing Title",
"author" : "Someone you have never heard of",
"url" : "http://www.theuselessweb.com",
"summary" : "a collection of useless websites",
"tag" : ["useless","maybe useful"]
}
Run Code Online (Sandbox Code Playgroud)
假设我有一个类似于上面所示的架构。用户要求应用程序显示一些“无用”的内容。
如何编写一个查询,通过标题、摘要和标签来查找“无用”一词作为模糊搜索?