我正在使用node.js和socket.io来创建聊天应用程序.如何将消息发送到另一个套接字,我只知道套接字的id或用户名.没有房间,客户一对一聊天.
在3x3格式中TableLayout有9 Buttons个.如何使用TableLayout(不是按钮ID)的id以编程方式访问这些按钮上的文本?
我已经为JLabel设置了相对于JPanel的位置(0,0).但它正在中心和顶部.我犯了什么错误?
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Main extends JFrame
{
private JPanel panel;
private JLabel label1;
public Main()
{
panel = new JPanel();
panel.setBackground(Color.YELLOW);
ImageIcon icon1 = new ImageIcon("3.png");
label1 = new JLabel(icon1);
label1.setLocation(0,0);
panel.add(label1);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().add(panel);
this.setSize(500,500);
this.setVisible(true);
}
public static void main (String[] args) {
new Main();
}
}
Run Code Online (Sandbox Code Playgroud) 我知道HTML元素的名称,但不知道id.如何使用Javascript使用元素的名称获取id.请帮助.
我ImageAdapter extends BaseAdapter用来膨胀一个gridview.Gridview有两个textview.我想为其中一个设置自定义字体.使用Typeface font = Typeface.createFromAsset(getAssets(), "BABYCAKE.TTF");in ImageAdapter会出错The method getAssets() is undefined for the type ImageAdapter.
ImageAdapter 被定义为
package com.amit.wozzle;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.view.LayoutInflater;
public class ImageAdapter extends BaseAdapter
{
private ArrayList<String> listCountry;
private ArrayList<String> scorestage;
private Activity activity;
Typeface font;
public ImageAdapter(Activity activity,ArrayList<String> listCountry, ArrayList<String> scorestage) …Run Code Online (Sandbox Code Playgroud) 是否可以一次性为整个Android应用程序设置自定义字体.我的意思是我不想setTypeFace在每个活动中使用每个textview.不仅是文本视图,还有每个可能的文本.
在下面的代码中,它viewflipper并没有占据整个屏幕,它只是围绕着textview. 为什么会发生这种情况?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0000ff" >
<ViewFlipper android:id="@+id/ViewFlipper01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#aa0000"
android:layout_gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"></TextView>
</ViewFlipper>
</ScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我正在尝试显示类主教的对象的ImageIcon.使用getImage()检索ImageIcon.返回的ImageIcon存储在引用m中但它没有显示,并且正在显示另一个直接加载的ImageIcon h.我犯了什么错误?
import javax.swing.*;
//Game.java
public class Game {
public static void main(String[] args) {
board b = new board();
bishop bis1 = new bishop();
bis1.setLocation(0, 0);
ImageIcon m = bis1.getImage();
b.squares[0][1].add(new JLabel(m));
ImageIcon h = new ImageIcon("rook.png");
b.squares[0][0].add(new JLabel(h));
}
}
//bishop.java
import javax.swing.*;
import java.awt.*;
public class bishop {
private ImageIcon img;
private int row;
private int col;
public void bishop() {
img = new ImageIcon("bishop.png");
}
public void setLocation(int i, int j) {
row = i;
col …Run Code Online (Sandbox Code Playgroud)